Cross Chain Swaps from Solana
The 0x Cross-Chain API is in private beta. Request access to start building.
Quick link with examples: 0x-examples
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:
- Fetch a quote
- Sign and send a transaction
- Monitor the status of the cross chain swap
In our example, we will be swapping WSOL on Solana to USDC on Base. For understanding how to deal with the native SOL, please refer to Native Tokens Handling.
0. Prerequisites
Make sure you have:
- A funded Solana wallet
- 0x API key
- An RPC Connection (see details below)
Set up an RPC connection
Solana provides a default public RPC endpoint, but for production use, it’s strongly recommended to run your own or use a third-party provider like Helius.
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.
Example response
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.
Example response
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.