Skip to main content
This example demonstrates a complete cross-chain transfer from Base to Optimism using TypeScript and viem.

Prerequisites

  • Node.js 18+
  • An API key from LayerZero
  • A funded wallet on Base (source chain)

Installation

Environment setup

Create a .env file in your project root:

1

Validate transfer path

Before requesting a quote, verify that the destination token is reachable from your source token.Query the tokens endpoint with filters to check if your destination exists in the list of transferrable tokens:
Why validate first? Validating the transfer path before requesting quotes prevents unnecessary API calls and provides immediate feedback if a route doesn’t exist.
2

Get quotes

Request a quote for your cross-chain transfer. The API returns available routes with fees, amounts and estimated duration.
Quote response structure:
3

Build user steps

When the user confirms a quote, call /build-user-steps with the ID of that quote. The response contains the userSteps to execute.
Do not execute userSteps from the /quotes response. Quotes for new API keys and quotes on solver routes do not include them. If a quote includes userSteps, /build-user-steps usually returns the same steps. Always execute the steps that /build-user-steps returns. See Build User Steps.
Build user steps response structure:For a native token transfer (for example, ETH), the response contains one bridge step. For an ERC20 transfer (for example, USDC), the response contains zero, one or two approve steps, followed by one bridge step. See Executing userSteps safely.
4

Execute user steps

Process each user step from the /build-user-steps response. Execute them in order.
Do not approve LZMultiCall as a token spenderAny address can call LZMultiCall with any list of calls, so any address can spend an allowance granted to it and can transfer any tokens or native currency it holds. You MUST NOT grant an allowance to LZMultiCall, and you MUST NOT transfer assets to its address.The API sets the spender in each approve step: TransferDelegate on routes that execute through LZMultiCall, and the bridge contract on other routes. You MUST execute each userStep in the order returned, with to, data and value unchanged. The API does not support modified or rebuilt calldata.See Contracts Overview for the contract architecture.
Step types: Most EVM routes use TRANSACTION steps. Intent-based routes (like Aori) may include SIGNATURE steps for EIP-712 signed messages.
5

Track transfer status

Poll the status endpoint until the transfer completes. The API returns the current status and explorer link.
Status values:

Complete example

Next steps