API for building and executing PumpSwap v2 transactions on Solana
The SwapV2 API provides a robust, production-ready solution for building buy and sell transactions for Pump and PumpV2 tokens on the Solana blockchain. The API intelligently detects whether a token is on the bonding curve or has migrated to PumpSwap, ensuring the correct transaction type is used automatically.
Key Features:
http://swap-api.swapv2.fun
/api/buy
Buy Tokens
Build a transaction to buy tokens with SOL.
| Parameter | Type | Required | Description |
|---|---|---|---|
userPublicKey |
string | Yes | Your Solana wallet public key |
mintAddress |
string | Yes | Token contract address (CA) to buy |
solAmount |
number | Yes | Amount of SOL to spend |
slippage |
number | No | Slippage tolerance in percentage (default: 1) |
priorityFee |
number | No | Priority fee in SOL (default: 0.001) |
tipAmount |
number | No | MEV protection tip in SOL (default: 0.001, min: 0.0002) |
POST /api/buy
Content-Type: application/json
{
"userPublicKey": "YourSolanaPublicKey",
"mintAddress": "TokenContractAddress",
"solAmount": 0.1,
"slippage": 1,
"priorityFee": 0.001,
"tipAmount": 0.001
}
{
"success": true,
"transaction": "base64EncodedTransactionString",
"blockhash": "blockhash",
"lastValidBlockHeight": 123456789,
"message": "Transaction built successfully. Sign and send this transaction to execute the buy."
}
/api/sell
Sell Tokens
Build a transaction to sell tokens for SOL.
| Parameter | Type | Required | Description |
|---|---|---|---|
userPublicKey |
string | Yes | Your Solana wallet public key |
mintAddress |
string | Yes | Token contract address (CA) to sell |
tokenAmount |
number | Yes | Amount of tokens to sell |
slippage |
number | No | Slippage tolerance in percentage (default: 1) |
priorityFee |
number | No | Priority fee in SOL (default: 0.001) |
tipAmount |
number | No | MEV protection tip in SOL (default: 0.001, min: 0.0002) |
POST /api/sell
Content-Type: application/json
{
"userPublicKey": "YourSolanaPublicKey",
"mintAddress": "TokenContractAddress",
"tokenAmount": 1000,
"slippage": 1,
"priorityFee": 0.001,
"tipAmount": 0.001
}
{
"success": true,
"transaction": "base64EncodedTransactionString",
"blockhash": "blockhash",
"lastValidBlockHeight": 123456789,
"message": "Transaction built successfully. Sign and send this transaction to execute the sell."
}
/api/health
Health Check
Check if the API server is running.
{
"status": "ok",
"timestamp": "2025-01-XX..."
}
// Buy tokens
const response = await fetch('https://swap-api.swapv2.fun/api/buy', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userPublicKey: 'YourPublicKey',
mintAddress: 'TokenCA',
solAmount: 0.1,
slippage: 1,
priorityFee: 0.001,
tipAmount: 0.001
})
});
const data = await response.json();
if (data.success) {
// Deserialize the transaction
const transaction = VersionedTransaction.deserialize(
Buffer.from(data.transaction, 'base64')
);
// Sign with your wallet
const signed = await wallet.signTransaction(transaction);
// Send transaction
const signature = await connection.sendRawTransaction(signed.serialize());
console.log('Transaction signature:', signature);
}
If an error occurs, the API will return a response with success: false and an error message:
{
"success": false,
"error": "Error message describing what went wrong"
}
Common HTTP status codes:
200 - Success400 - Bad Request (missing or invalid parameters)500 - Internal Server ErrorB15x4tPy3b8cb4258qeF5k7VqEsPmRfMypMi5Np7T3vU