bridge()
SET UP THE SDK BEFORE YOU START:
- You can find the SDK setup instructions in the Quickstart page.
- We also created a tutorial to make it easier to understand how devs need to initialize the Nexus SDK in their project.
Use the bridge()
function to bridge a specific token from one (or many) chains to a single chain.
Method signature
Typescript
async bridge(params: BridgeParams): Promise<BridgeResult>
async simulateBridge(params: BridgeParams): Promise<SimulationResult>
Parameters
Typescript
/**
* Parameters for bridging tokens.
*/
export interface BridgeParams {
token: SUPPORTED_TOKENS;
amount: number | string;
chainId: SUPPORTED_CHAINS_IDS;
gas?: bigint;
sourceChains?: number[];
}
chainID
refers to the Chain ID of the recipient chain.sourceChains
is an optional param that takes an array of chainIDs. Use this if you want only some of your funds to be used for bridging.. Helpful if you want to maintain your holdings on some chains.
Example
Typescript
import type { BridgeParams, BridgeResult, SimulationResult } from '@avail-project/nexus-core';
// Bridge tokens between chains
const result: BridgeResult = await sdk.bridge({
token: 'USDC',
amount: 100,
chainId: 137,
sourceChains: [84532, 80002], // Only use USDC from `Base Sepolia` and `Polygon Amoy` as sources for the bridge
} as BridgeParams);
// Simulate bridge to preview costs
// Note that you can avoid using optional params
const simulation: SimulationResult = await sdk.simulateBridge({
token: 'USDC',
amount: 100,
chainId: 137,
});
Return Value
The return value is a BridgeResult
object, which is a union type.
Typescript
/**
* Result structure for bridge transactions.
*/
export type BridgeResult =
| {
success: false;
error: string;
}
| {
success: true;
explorerUrl: string;
transactionHash?: string;
};
Last updated on