Solana Token Swaps via API
We're excited to announce native Solana token swap support! Swap any SPL token on Solana Mainnet, EVM-friendly I/O.
What's New
GET /v1/solana/swap - Get Swap Quote
Get a quote for swapping Solana tokens without executing the transaction. See the expected output amount, USD values, and slippage before committing.
Example: Get quote to swap 0.1 SOL for USDC
curl -X GET "https://api.thirdweb.com/v1/solana/swap?address=YOUR_WALLET_ADDRESS&tokenIn=So11111111111111111111111111111111111111112&tokenOut=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&amount=100000000&chainId=solana:mainnet" \
-H "x-secret-key: YOUR_SECRET_KEY"
Response:
{
"result": {
"inputMint": "So11111111111111111111111111111111111111112",
"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"inputAmount": "100000000",
"outputAmount": "15423156",
"inputUsdValue": 15.45,
"outputUsdValue": 15.42,
"slippageBps": 34,
"requestId": "019a5f00-fab2-747d-bba2-b77f993314a0"
}
}
POST /v1/solana/swap - Execute Swap
Execute a complete token swap with automatic signing, execution, and on-chain confirmation. The swap is confirmed on Solana within 30 seconds or returns a timeout error.
Example: Swap 0.1 SOL for USDC
curl -X POST "https://api.thirdweb.com/v1/solana/swap" \
-H "Content-Type: application/json" \
-H "x-secret-key: YOUR_SECRET_KEY" \
-d '{
"address": "YOUR_WALLET_ADDRESS",
"tokenIn": "So11111111111111111111111111111111111111112",
"tokenOut": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"amount": "100000000",
"chainId": "solana:mainnet"
}'
Response:
{
"result": {
"signature": "5ttCNobho7nk5F1Hh4pU4d9T2o1yAFn3p1w8z8jk2jKd9KWCKN6dzyuT5xP1ny4wz9f5xCLjAF6Y9s9EoTW4aE1X",
"inputMint": "So11111111111111111111111111111111111111112",
"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"inputAmount": "100000000",
"outputAmount": "15423156",
"inputUsdValue": 15.45,
"outputUsdValue": 15.42,
"requestId": "019a5f00-fab2-747d-bba2-b77f993314a0"
}
}
View transaction: https://solscan.io/tx/5ttCNobho7nk5F1Hh4pU4d9T2o1yAFn3p1w8z8jk2jKd9KWCKN6dzyuT5xP1ny4wz9f5xCLjAF6Y9s9EoTW4aE1X
Key Features
✨ Aggregated Liquidity - Best prices across multiple DEXs and liquidity sources
💰 USD Value Display - See real-time USD values for input and output amounts
⚡ Automatic Execution - No need to manually sign or submit transactions
🔒 Confirmed Results - Returns only after transaction is confirmed on-chain
🌐 Mainnet Only - Swaps available on Solana mainnet (solana:mainnet)
💸 Gasless Support - Qualifying swaps ($10+ with <0.01 SOL) may be gasless
Common Token Addresses
| Token | Mint Address |
|---|---|
| SOL | So11111111111111111111111111111111111111112 |
| USDC | EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v |
| USDT | Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB |
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
address |
string | Yes | Wallet address executing the swap |
tokenIn |
string | Yes | Input token mint address (token being sold) |
tokenOut |
string | Yes | Output token mint address (token being bought) |
amount |
string | Yes | Amount in smallest unit (e.g., lamports for SOL) |
chainId |
string | Yes | Must be solana:mainnet |
Response Fields
| Field | Type | Description |
|---|---|---|
signature |
string | Transaction signature (POST only) |
inputMint |
string | Input token mint address |
outputMint |
string | Output token mint address |
inputAmount |
string | Amount of input token swapped |
outputAmount |
string | Amount of output token received |
inputUsdValue |
number | USD value of input amount |
outputUsdValue |
number | USD value of output amount |
slippageBps |
number | Slippage tolerance in basis points |
requestId |
string | Unique request identifier |
Amount Formatting
Amounts must be in the token's smallest unit (before decimals):
- SOL (9 decimals): 1 SOL =
1000000000lamports ="1000000000" - USDC (6 decimals): 1 USDC =
1000000="1000000" - 0.1 SOL:
"100000000"(100 million lamports) - 10 USDC:
"10000000"(10 million)
Error Handling
The API returns detailed error messages for common issues:
Insufficient Balance:
{
"error": {
"message": "Insufficient funds",
"statusCode": 400
}
}
Minimum Swap Amount ($10+ for gasless):
{
"error": {
"message": "Minimum $10 for gasless",
"statusCode": 400
}
}
Transaction Timeout:
{
"error": {
"message": "Swap transaction was not confirmed within timeout period",
"statusCode": 504
}
}
Ready to start swapping? Check out the full API documentation for more details.