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

bridgeAndExecute()

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 bridgeAndExecute() function to bridge a token and execute a contract function on the recipient chain in a single flow. Use the simulateBridgeAndExecute() function to simulate bridgeAndExecute() before sending an actual transaction.

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

Method signature

Typescript
async bridgeAndExecute( params: BridgeAndExecuteParams, options?: OnEventParam, ): Promise<BridgeAndExecuteResult> async simulateBridgeAndExecute( params: BridgeAndExecuteParams, ): Promise<BridgeAndExecuteSimulationResult>

Parameters

Typescript
export interface BridgeAndExecuteParams { toChainId: number; token: string; amount: bigint; sourceChains?: number[]; execute: Omit<ExecuteParams, 'toChainId'>; enableTransactionPolling?: boolean; transactionTimeout?: number; waitForReceipt?: boolean; receiptTimeout?: number; requiredConfirmations?: number; recentApprovalTxHash?: string; }
  • BridgeAndExecuteParams: Parameters for using the bridgeAndExecute() function.

    • toChainId (number, required): The chain ID of the destination chain.
    • token (string, required): The token to be bridged in this flow.
    • amount (bigint, required): The amount of tokens to be used in this flow.
    • sourceChains (number[], optional): The chain IDs of the source chains to be used for the bridge. Useful if you want to maintain your holdings on some chains.
    • execute (Omit<ExecuteParams>, ‘toChainId’>, required): To be filled later
    • enableTransactionPolling (boolean, optional): Whether to enable transaction polling. Defaults to false.
    • transactionTimeout (number, optional): To be filled later
    • waitForReceipt (boolean, optional): To be filled later
    • receiptTimeout (number, optional): To be filled later
    • requiredConfirmations (number, optional): To be filled later
    • recentApprovalTxHash (string, optional): To be filled later
  • options: Optional parameters for the event listener.

Example

Typescript
import type { BridgeAndExecuteParams, BridgeAndExecuteResult, OnEventParam } from '@avail-project/nexus-core'; // Direct contract execution const result = await sdk.execute({ toChainId: 1, to: '0xc3d688B66703497DAA19211EEdff47f25384cdc3', data: '0x...', tokenApproval: { token: 'USDC', amount: 1000000n }, }); // Bridge and execute const result2 = await sdk.bridgeAndExecute({ token: 'USDC', amount: 100_000_000n, toChainId: 1, sourceChains: [8453], execute: { to: '0xa354F35829Ae975e850e23e9615b11Da1B3dC4DE', data: '0x...', tokenApproval: { token: 'USDC', amount: 100_000_000n }, }, });

Return Value

The return value is a BridgeAndExecuteResult object.

Typescript
export type BridgeAndExecuteResult = { executeTransactionHash: string; executeExplorerUrl: string; approvalTransactionHash?: string; bridgeExplorerUrl?: string; // undefined when bridge is skipped toChainId: number; bridgeSkipped: boolean; // indicates if bridge was skipped due to sufficient funds };
Last updated on