Bridge and Execute Flows
Call bridge(params, options?)
- Use to move tokens cross-chain (intent-based bridge).
- Signature:
sdk.bridge(params, { onEvent? })
- Params (
BridgeParams):toTokenSymbol: string— token symbol (e.g., "ETH", "USDC")toAmountRaw: bigint— smallest unitstoChainId: number— destination chain idrecipient?: Hex— defaults to connected user addresstoNativeAmountRaw?: bigint— optional native token outputsources?: number[]— restrict source chains
- Result (
BridgeResult):intentExplorerUrl: stringsourceTxs: { chain, txHash, txExplorerUrl }[]intent: BridgeIntent
Call bridgeAndTransfer(params, options?)
- Use to bridge and transfer to a recipient address.
- Signature:
sdk.bridgeAndTransfer(params, { onEvent? })
- Params (
TransferParams):toTokenSymbol: stringtoAmountRaw: biginttoChainId: numberrecipient: Hexsources?: number[]
- Result (
TransferResult):- Transfer result follows
BridgeAndExecuteResult.
- Transfer result follows
Call bridgeAndExecute(params, options?)
- Use to bridge (if needed) and then execute a contract call.
- Signature:
sdk.bridgeAndExecute(params, { onEvent?, beforeExecute? })
- Params (
BridgeAndExecuteParams):toTokenSymbol: string,toAmountRaw: bigint,toChainId: numberexecute: Omit<ExecuteParams, "toChainId">- Optional:
waitForReceipt,requiredConfirmations, timeouts
beforeExecutehook (optional):beforeExecute?: () => Promise<{ value?: bigint; data?: Hex; gas?: bigint }>- Use to dynamically override execute payload before sending.
- Result (
BridgeAndExecuteResult):executetransaction result and optionalapprovaltransaction result- bridge result fields when a bridge was required
bridgeSkipped: booleanintent?: BridgeIntent
Call execute(params, options?)
- Use for a standalone contract call on a chain.
- Signature:
sdk.execute(params, { onEvent? })
- Params (
ExecuteParams):toChainId: numberto: Hex(contract address)data?: Hexvalue?: bigintgas?: bigint(optional but recommended for deterministic behavior)gasPrice?: 'low' | 'medium' | 'high'- Optional receipt config:
waitForReceipt,receiptTimeout,requiredConfirmations - Optional
tokenApproval?: { toTokenSymbol: string; amount: bigint; spender: Hex }
- Result (
ExecuteResult):execute, optionalapproval, andchainId- optional receipt fields
Use simulation helpers
- Call
sdk.simulateBridge(params)→SimulationResult. - Call
sdk.simulateBridgeAndTransfer(params)→BridgeAndExecuteSimulationResult. - Call
sdk.simulateBridgeAndExecute(params)→BridgeAndExecuteSimulationResult. - Use simulation to show fees and gas before execution.
- Expect
BridgeAndExecuteSimulationResult.bridgeSimulationto benullif bridge is skipped.
Compute max bridgeable amount
- Call
sdk.calculateMaxForBridge({ toTokenSymbol, toChainId, recipient?, sources? }). - Use
BridgeMaxResultto set “max” or validate input.
Convert amounts to bigint
- Use
sdk.convertTokenReadableAmountToBigInt(amountString, tokenSymbol, chainId). - Or use
sdk.utils.parseUnits(value, decimals)if decimals are known.
Attach hooks and events
- Attach intent and allowance hooks before calling bridge flows.
- Use
NEXUS_EVENTS.STEPS_LISTandNEXUS_EVENTS.STEP_COMPLETEfor progress UI.
Handle common failures
- On throw, clear intent/allowance refs and reset UI state.
- On user cancel, call
deny()on the active hook and abort.