Skip to content

PumpSwap Swap Endpoint

POST /api/v1/pumpswap/swap

Request Body

ParameterTypeDescription
userAddressstringThe Solana wallet address of the user executing the swap
tokenAddressstringThe address of the token to swap (also called mint or CA)
tokenAmountnumberThe amount of tokens, required for sells only. Yea, you cannot buy an exact amount of tokens with this endpoint, sorry.
solThresholdnumberThe maximum SOL amount threshold for the swap, required for buys only.
isBuybooleanWhether this is a buy (true) or sell (false) operation
computePricenumberOptional. Sets total compute limit to be allocated for all instructions within the created tx.
computeLimitnumberOptional. Sets compute price in Lamports to be included as a part of the tx, known as priority fee.

Examples

js
const swapData = {
    userAddress: "dafs3GGvJoUYjTmxRXhkqCj3ULa9bvKmX7EDDMTwVFE",
    tokenAddress: "3YUErHCx6jf56kPAXAWrRBwpMQJhaShj494ckZmcpump",
    solThreshold: 1.5,
    tokenAmount: 100000,
    isBuy: false
};

async function getSwapTX() {
    try {
        const response = await fetch('https://api.degen.ing/api/v1/pumpswap/swap', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(swapData)
        });

        const result = await response.json();
        console.log('Swap tx base64:', result.transaction.content);
    } catch (error) {
        console.error('Error requesting swap tx:', error);
    }
}
bash
curl -X POST \
  -H 'Content-Type: application/json' \
  'https://api.degen.ing/api/v1/pumpswap/swap' \
  -d '{
    "userAddress": "dafs3GGvJoUYjTmxRXhkqCj3ULa9bvKmX7EDDMTwVFE",
    "tokenAddress": "3YUErHCx6jf56kPAXAWrRBwpMQJhaShj494ckZmcpump",
    "solThreshold": 1.5,
    "tokenAmount": 100000,
    "isBuy": false
}'

Response

json
{"transaction": { "content": "<base64 encoded transaction>" } }

Implementation Notes

  • It uses the same WSol account for a given token
  • It closes the WSol account after each swap, so if you already have some WSol, the tx will exchange them back to Sol
  • It gets the price of the token from pools, aiming for the best price. That's why on buy you do not need to provide tokenAmount parameter. Contact the dev if you need it, we can add an option for you.