Skip to Content
Avail Nexus is now live! Check out our docs to get started.

bridgeAndTransfer()

SET UP THE SDK BEFORE YOU START:

  1. You can find the SDK setup instructions in the Quickstart page.
  2. We also created a tutorial to make it easier to understand how devs need to initialize the Nexus SDK in their project.

Use the bridgeAndTransfer() function to source a token from multiple source chains to a single destination chain. Use the simulateBridgeAndTransfer() function to simulate the bridge and transfer transaction to preview the costs and fees, before actually executing the transaction.

Note: Check out the API reference for a full list of supported tokens and chains.

Method signature

Typescript
async bridgeAndTransfer( params: TransferParams, options?: { onEvent?: (event: { name: 'STEPS_LIST' | 'STEP_COMPLETE' | 'SWAP_STEP_COMPLETE'; args: unknown }) => void } ): Promise<TransferResult> async simulateBridgeAndTransfer( params: TransferParams, ): Promise<BridgeAndExecuteSimulationResult>

Parameters

Typescript
/** * Parameters for bridging and transferring tokens. */ export interface TransferParams { token: string; amount: string; chainId: number; recipient: `0x${string}`; sourceChains?: number[]; }
  • TransferParams: Parameters for transferring tokens.
    • token (string, required): The token to be bridged and transferred.
    • amount (string, required): The amount of tokens to be bridged and transferred.
    • chainId (number, required): The chain ID of the destination chain.
    • recipient (0x${string}, required): The recipient address.
    • sourceChains (number[], optional): The chain IDs of the source chains to be used for the transfer. Useful if you want to maintain your holdings on some chains.
  • options: Optional parameters for the event listener.

Example

Typescript
import type { TransferParams, TransferResult, SimulationResult } from '@avail-project/nexus-core'; // Smart transfer with automatic optimization const bridgeAndTransferResult = await sdk.bridgeAndTransfer( { token: 'ETH', amount: "1.5", chainId: 1, // Ethereum recipient: '0x742d35Cc6634C0532925a3b8D4C9db96c4b4Db45', }, { onEvent: (event) => { if (event.name === NEXUS_EVENTS.STEPS_LIST) console.log('Transfer steps:', event.args); if (event.name === NEXUS_EVENTS.STEP_COMPLETE) console.log('Step completed:', event.args); }, }, ); const bridgeAndTransferSimulation = await sdk.simulateBridgeAndTransfer({ token: 'ETH', amount: "1.5", chainId: 1, recipient: '0x742d35Cc6634C0532925a3b8D4C9db96c4b4Db45', }); console.log('Bridge and transfer simulation:', bridgeAndTransferSimulation);

Return Value

bridgeAndTransfer()

The return value is a TransferResult object.

Typescript
/** * Result structure for transfer transactions. */ export type TransferResult = { transactionHash: string; explorerUrl: string; };

simulateBridgeAndTransfer()

The return value is a BridgeAndExecuteSimulationResult object.

Typescript
export type BridgeAndExecuteSimulationResult = { bridgeSimulation: SimulationResult | null; executeSimulation: ExecuteSimulation; };
Last updated on