Get started

Learn how to use the 0x Cross Chain API endpoint to get a quote, set allowance, and send a cross chain swap transaction.

circle-check

About 0x Cross Chain API

The 0x Cross Chain API is a fast, flexible API that lets developers programatically access tokens across various blockchains, enabling cross-chain swap functionality in any app or wallet.

Whether you're building a new application, or expanding the offering of your existing product, this API helps you integrate cross-chain token swaps with minimal overhead and maximum efficiency.

Steps to Cross Chain Swap Tokens

This guide will walk you through using the /quotes and /status endpoints on 0x’s Cross Chain API to:

  1. Fetch a quote

  2. Set allowance

  3. Sign and send a transaction

  4. Monitor the status of the cross chain swap

In our example, we will be swapping WETH on Base to USDC on Arbitrum.

0. Prerequisites

Make sure you have:

chevron-rightSetting up wallet and RPC connectionhashtag

Base provides a default public RPC endpointarrow-up-right, but for production use, it's strongly recommended to run your own or use a third-party provider like QuickNodearrow-up-right or Alchemyarrow-up-right.

To interact with that RPC, we will use a popular TS library, viemarrow-up-right.

1. Fetch a Quote

Start by sending a GET request to the 0x /quotes endpoint to get a quote for a specific tokens and chains pair with selected amount.

chevron-rightExample responsehashtag

2. Set a token allowance

It is possible, that you will need to set proper token allowance to 0x's AllowanceHolder contractarrow-up-right. In cases where allowance will be needed, it will be reported in issues in the response.

Below you can find an example on how to set proper token allowance for received quote.

3. Sign and submit a transaction

Now that we have both the approval and the quote, we can construct, sign, and submit the transaction. Optionally, after the approval, you might want to re-fetch a fresh quote.

Code below will construct, sign, and submit the transaction based on the quote response.

4. Monitor the cross chain execution

The last step is to monitor the execution of the cross chain transaction, including the fill on the destination chain. For that, we will use the /status endpoint.

In your application, you might need to monitor the status repeatedly, as bridging operation might take several seconds or minutes to complete.

chevron-rightExample responsehashtag

Last updated