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, estimated duration, and the steps needed to execute.
Quote response structure:For native token transfers (like ETH), the response contains a single bridge step. For ERC20 transfers (like USDC), the response contains two steps — an approve followed by a bridge. See Executing userSteps safely for details on the two-step flow.
3

Execute user steps

Process each user step in the quote. The quote contains an array of steps—execute them in order.
Never approve the LZMulticall (Wrapper) as a token spenderLZMulticall executes bridge transactions. It is not the right spender, and approving it will lose you tokens. The correct spender is the TransferDelegate, and the API’s approve step already has this set in the calldata. Execute every userStep as returned.See Contracts Overview for details on 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.
4

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