Intents

Token Transfer

Learn how to create token transfer operations using the Okto TypeScript SDK.

The tokenTransfer() function creates a user operation for transferring tokens. This function initiates the process of transferring a token by encoding the necessary parameters into a User Operation, which can then be signed and executed using the OktoClient.

Available on

Ethereum
Ethereum
Polygon
Polygon
Avalanche
Avalanche
Arbitrum
Arbitrum
BSC
BSC
Fantom
Fantom
Linea
Linea
Metis
Metis
Optimism
Optimism
Base
Base
Base Sepolia
Base Sepolia
HyperEVM Testnet
HyperEVM Testnet
Polygon Amoy
Polygon Amoy

To enable these chains for your application, please configure them in the Okto Dashboard.

Not available on

There are two ways to implement token transfers:

  • Abstracted Flow: A simplified approach where the user operation is automatically created, signed, and executed in a single step. Perfect for most applications.
  • UserOp Flow: A granular approach where you manually control the creation, signing, and execution of the user operation. Useful for custom implementations or advanced use cases.

Example

import { tokenTransfer } from "@okto_web3/core-js-sdk"; 
 
async function handleTokenTransfer() {
    try {
        const transferParams = { 
            amount: BigInt("1000000000000000000"), // 1 token with 18 decimals 
            recipient: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", 
            token: "0x2170ed0880ac9a755fd29b2688956bd959f933f8", // Token contract address 
            caip2Id: "eip155:1"
        }; 
 
        // Execute the transfer
        const jobId = await tokenTransfer(oktoClient, transferParams); 
        console.log('Transfer jobId:', jobId);
    } catch (error) {
        console.error('Error in token transfer:', error);
    }
}

Note

For error handling:

Method Overview

MethodDescription
async tokenTransferCreate a user operation for token transfer

Token Transfer

async tokenTransfer(oktoClient: OktoClient, data: TokenTransferIntentParams) creates a user operation for transferring tokens.

Parameters

ParameterTypeDescriptionRequired
oktoClientOktoClientInstance of OktoClientYes
dataTokenTransferIntentParamsParameters for the token transferYes

Where TokenTransferIntentParams contains:

FieldTypeDescriptionRequired
amountnumber | bigintAmount to send, in the smallest unit (e.g., gwei for ETH)Yes
recipientAddressWallet address of the recipientYes
tokenAddress | ''The token address for the transactionYes
caip2IdstringThe network ID (e.g., Ethereum - eip155:1, Polygon - eip155:137)Yes

Response

Success Response

Field NameTypeDescription
resultPromise<string>Returns the jobId for the token transfer

On this page