The 0x Solana Swap API is available via priority access. Apply now to start building.
Quick link for example code: link
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.
This guide will walk you through using the /swap-instructions endpoint on 0x’s Solana API to:
VersionedTransaction on Solana mainnetMake sure you have:
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.
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.
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.
For the complete list of required request parameters, see the API Reference.
For a sample response, complete schema, and detailed field descriptions, see the API Reference.
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:
Here’s how to decode them using @solana/web3.js:
pubkey from byte array to a PublicKeyTransactionInstruction objects needed to build your Solana transactionBefore 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:
AddressLookupTableAccountcompileToV0Message(...)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.
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.
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.
Coming from another swap provider? Make sure to review the following:
[TODO]