transfer()
SET UP THE SDK BEFORE YOU START:
You can find the SDK setup instructions in the Overview page.
Use the transfer()
function to transfer tokens to a specific recipient across all supported chains.
Parameters
TransferParams
is an object that contains the following properties:
Typescript
/**
* Parameters for transferring tokens.
*/
export interface TransferParams {
token: SUPPORTED_TOKENS;
amount: number | string;
chainId: SUPPORTED_CHAINS_IDS;
recipient: `0x${string}`;
}
Example
Typescript
import type { TransferParams, TransferResult } from '@avail-project/nexus';
// Smart transfer with automatic optimization
const result: TransferResult = await sdk.transfer({
token: 'USDC',
amount: 100,
chainId: 42161, // Arbitrum
recipient: '0x...',
} as TransferParams);
// The SDK automatically:
// 1. Checks if you have USDC + ETH for gas on Arbitrum
// 2. Uses direct EVM transfer if available (faster, cheaper)
// 3. Falls back to chain abstraction if local funds insufficient
// Simulate transfer to preview costs and optimization path
const simulation: SimulationResult = await sdk.simulateTransfer({
token: 'USDC',
amount: 100,
chainId: 42161,
recipient: '0x...',
});
// Check if direct transfer will be used
console.log('Fees:', simulation.intent.fees);
// For direct transfers: gasSupplied shows actual native token cost
// For CA transfers: includes additional CA routing fees
Return Value
Typescript
/**
* Result structure for transfer transactions.
*/
export interface TransferResult {
success: boolean;
error?: string;
explorerUrl?: string;
}
Last updated on