Integration Guide
This docs give a brief about the how to integrate Epoch's API into your dapp
Overview
This guide covers the specific integration for Epoch Intents:
Creating task data using
getTaskData()Performing deposit and register intent in one operation using
depositAndRegisterIntent()
Prerequisites
Node.js >= 18
Backend API endpoint - http://localhost:3000 (Will share the endpoint)
Wallet connected via Viem
Installation
npm install @epoch-protocol/epoch-compact-sdkCore Integration Pattern
1. Initialize the SDK
import { EpochIntentSDK } from '@epoch-intents/compact-sdk';
import { useWalletClient } from 'viem';
function MyComponent() {
const { data: walletClient } = useWalletClient();
const publicClient = usePublicClient();
const { address } = useAccount();
const chainId = useChainId();
// Initialize SDK
const epochSdk = new EpochIntentSDK({
apiBaseUrl: '<http://localhost:3000>',
walletClient: walletClient as any,
});
}2. Create Task Data
3. Execute Deposit + Register Intent
API Reference
EpochIntentSDK.getTaskData()
Creates task data for token swap operations.
Parameters:
taskType- AlwaysTaskType.GetTokenOutfor nowtaskData- Task data object depending on the task type
taskData for GetTokenOut Task -
taskData.depositTokenAddress- Address of token to deposittaskData.tokenInAmount- Amount to deposit (as bigint)taskData.outputTokenAddress- Address of desired output tokentaskData.minTokenOut- Minimum amount expected out (as bigint)taskData.destinationChainId- Target chain ID
Returns:
taskTypeString- EIP-712 type string for task datataskData- Task data object with token swap parameters
EpochIntentSDK.depositAndRegisterIntent()
Performs deposit and register intent in one operation.
Parameters:
isNative- Whether depositing native tokenssponsorAddress- Address of the sponsor (user's wallet)taskTypeString- FromgetTaskData()resulttaskData- FromgetTaskData()result
Returns:
depositResult- Transaction hash and receiptintentResponse- Intent hash, signature, and digest
Last updated
Was this helpful?