PumpSwap v2 API

API for building and executing PumpSwap v2 transactions on Solana

Overview

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:

Base URL

http://swap-api.swapv2.fun

Endpoints

POST /api/buy Buy Tokens

Build a transaction to buy tokens with SOL.

Request Body

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)

Example Request

POST /api/buy
Content-Type: application/json

{
  "userPublicKey": "YourSolanaPublicKey",
  "mintAddress": "TokenContractAddress",
  "solAmount": 0.1,
  "slippage": 1,
  "priorityFee": 0.001,
  "tipAmount": 0.001
}

Example Response

{
  "success": true,
  "transaction": "base64EncodedTransactionString",
  "blockhash": "blockhash",
  "lastValidBlockHeight": 123456789,
  "message": "Transaction built successfully. Sign and send this transaction to execute the buy."
}

POST /api/sell Sell Tokens

Build a transaction to sell tokens for SOL.

Request Body

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)

Example Request

POST /api/sell
Content-Type: application/json

{
  "userPublicKey": "YourSolanaPublicKey",
  "mintAddress": "TokenContractAddress",
  "tokenAmount": 1000,
  "slippage": 1,
  "priorityFee": 0.001,
  "tipAmount": 0.001
}

Example Response

{
  "success": true,
  "transaction": "base64EncodedTransactionString",
  "blockhash": "blockhash",
  "lastValidBlockHeight": 123456789,
  "message": "Transaction built successfully. Sign and send this transaction to execute the sell."
}

GET /api/health Health Check

Check if the API server is running.

Example Response

{
  "status": "ok",
  "timestamp": "2025-01-XX..."
}

Usage Example (JavaScript)

// 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);
}

Error Handling

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:

Notes