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:

  1. Creating task data using getTaskData()

  2. Performing deposit and register intent in one operation using solveIntent()

Prerequisites

Installation

npm install @epoch-protocol/epoch-intents-sdk

Core 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: '<endpoint>',
    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 - Always TaskType.GetTokenOut for now

  • intentData - Intent data object depending on the task type

  • extraDataTypestring - (Optional) EIP-712 type string for additional data fields

  • extraData - (Optional) Additional data fields to include in the intent

intentData for GetTokenOut Task -

  • intentData.isNative - Whether depositing native tokens

  • intentData.depositTokenAddress - Address of token to deposit

  • intentData.tokenInAmount - Amount to deposit (as string, e.g., from parseUnits().toString())

  • intentData.outputTokenAddress - Address of desired output token

  • intentData.minTokenOut - Minimum amount expected out (as string, e.g., from parseUnits().toString())

  • intentData.destinationChainId - Target chain ID (as string)

  • intentData.protocolHashIdentifier - Protocol hash identifier (32-byte hex string)

  • intentData.recipient - Recipient address for the output tokens

Returns:

  • taskTypeString - EIP-712 type string for task data

  • intentData - Task data object with token swap parameters

EpochIntentSDK.solveIntent()

Performs deposit and register intent in one operation. This method handles the complete flow: checking if deposit is needed, performing deposit and registration if required, and creating the allocation.

Parameters:

  • isNative - Whether depositing native tokens

  • sponsorAddress - Address of the sponsor (user's wallet)

  • taskTypeString - From getTaskData() result

  • intentData - From getTaskData() result

  • sponsorSignature - (Optional) Sponsor signature (will be generated if not provided)

Returns:

If deposit is required:

  • depositResult - Transaction hash and receipt for deposit

  • intentRequestData - The compact request data

  • submittedIntentData - Intent hash, signature, and digest

  • getIntentStatus - Current intent status

  • retryIntentSolver - Function to retry intent solving

If deposit is not required:

  • transactions - Array of execution transactions

Tokens Supported

Last updated