Cross chain swaps from Solana

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

circle-check

Steps to Cross Chain Swap Tokens from Solana

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

  1. Fetch a quote

  2. Sign and send a transaction

  3. Monitor the status of the cross chain swap

In our example, we will be swapping WSOL on Solana to USDC on Base.

0. Prerequisites

Make sure you have:

chevron-rightSet up an RPC connectionhashtag

Solana 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 Heliusarrow-up-right.

import { Connection } from "@solana/web3.js";

// You can replace this with your own or a third-party RPC URL
const connection = new Connection("https://api.mainnet-beta.solana.com");

1. Fetch a Quote

Start by sending a GET request to the 0x /quotes endpoint to get a quotes for a specific tokens and chains pair with selected amount. You may use 'solana' or '999999999991' as the originChain.

chevron-rightExample responsehashtag

2. Sign and submit transaction

In the next step, you need to build VersionedTransaction based on returned transaction data, sign it with your wallet, and send it to the Solana network, and wait for transaction confirmation.

3. 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

Extra - using alternative gas payer

One thing that is specific to cross chain swaps originating from Solana is the ability to specify an alternative wallet as a gas payer. When requesting a /quote, you need to pass an extra gasPayer parameter, equal to base58-encoded pubkey of the gas payer. Then, when processing the response, you need to additionally sign the transaction with the gas payer wallet.

In the examples repo, you can find a dedicated end-to-end example utilising a gas payer functionality.

Last updated