Get Started
The 0x Solana Swap API is available via priority access. Apply now to start building.
Quick link for example code: link
About 0x Solana Swap API
The 0x Solana Swap API is a fast, flexible API that lets developers programmatically access the best token prices across Solana’s top DEXs, enabling seamless swap functionality in any app or wallet.
Whether you’re building a Solana-native experience or expanding an EVM-first product, the API helps you integrate token swaps with minimal overhead and maximum performance.
Steps to Swap Token
This guide will walk you through using the /swap-instructions endpoint on 0x’s Solana API to:
- Fetch a quote
- Build the swap instructions
- Sign and send a
VersionedTransactionon Solana mainnet
0. Prerequisites
Make sure you have:
- 0x API key
- A funded Solana keypair (see details below)
- A RPC Connection (see details below)
Setup a keypair
To sign and send transactions on Solana, you’ll need a valid keypair that has funds to swap (e.g. SOL). This represents the “taker” account executing the swap. For testing purposes, you can generate a new keypair locally or use an existing one by loading the private key from an environment variable.
Setup 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 POST request to the 0x /swap-instructions endpoint to get swap instructions for a specific token pair and input amount.
This endpoint returns everything needed to construct and execute a swap transaction.
Example request
Required Request Parameters
For the complete list of required request parameters, see the API Reference.
Example Response
For a sample response, complete schema, and detailed field descriptions, see the API Reference.
2. Build Swap Instructions
Once you have the quote, the response will include a list of serialized Solana instructions. These need to be deserialized into TransactionInstruction objects before you can add them to a transaction.
Each instruction includes:
- A list of accounts (with signer/writable metadata)
- A program ID
- Raw instruction data
Here’s how to decode them using @solana/web3.js:
What this does
- Decodes each
pubkeyfrom byte array to aPublicKey - Reconstructs all
TransactionInstructionobjects needed to build your Solana transaction
3. Resolve Address Lookup Tables
Before you compile and sign a v0 (VersionedTransaction), you need to resolve any Address Lookup Tables (ALTs) returned by the 0x /swap-instructions endpoint.
ALTs let Solana v0 transactions reference more accounts than can fit in the static account list by “looking up” additional addresses on-chain. If the quote response includes address_lookup_tables, you must:
- Fetch each lookup table account from RPC
- Deserialize it into an
AddressLookupTableAccount - Pass the resulting accounts into
compileToV0Message(...)
4. Sign and Send the Transaction
With your instructions ready, the final step is to wrap them in a VersionedTransaction, sign it with your wallet, and send it to the Solana network.
The 0x Solana API returns instructions that are compatible with the latest v0 transaction format, which supports address deduplication and future extensions.
Notes
- The transaction must be signed by the taker (payer of the swap)
- You’ll need a funded wallet that can cover gas (SOL)
- If you add extra instructions (compute budget, unwrap/cleanup, transfers, etc.), be mindful of the v0 transaction 1232-byte limit and use the Integrator Byte Costs guide to reserve bytes appropriately.
sendTransaction Options
When sending the signed transaction to the Solana network, there are a couple of important options you can configure to control how the RPC node handles it. These options can impact performance, reliability, and UX depending on your use case.
For example, if your use case is a payment solution where reliability is more important than speed, you might set a higher maxRetries to ensure the transaction has multiple attempts. For a fast-moving trading bot, you might prefer to set skipPreflight=true to reduce latency.
Transaction Confirmation
In addition, after sending the transaction, it is always best practice to check the transaction confirmation state. If the transaction fails, you should log the error for debugging or communicate it clearly with your users on your interface.
You can confirm the transaction using the confirmTransaction method with your chosen level of commitment - "finalized" , "confirmed", or "processed". Learn more about configuring state commitment levels to choose the right option for your use case.
For additional best practices on confirming transactions and handling errors, see the transaction confirmation tips guide.
Important Integration Notes
Coming from another swap provider? Make sure to review the following:
[TODO]