Local Transaction API
The Local Transaction API builds a transaction that you handle signing and sending yourself with a custom RPC endpoint. This gives you full security and control over your transactions.
Benefits
- Complete control over transaction signing
- Use your own RPC endpoint
- Higher security for sensitive operations
- Full transaction customization
API Endpoints
Build Trading Transaction
POST https://pumpswapapi.fun/api/trade/trade-local
Generates an unsigned transaction for buying or selling tokens.
Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
publicKey | string | Yes | The public key of your wallet |
action | string | Yes | Trade action: 'buy' or 'sell' |
mint | string | Yes | Token address/mint |
amount | string | Yes | Amount to trade (can include % for sell) |
amountType | string | Yes | 'sol' for buy operations, 'token' for sell operations |
pool | string | Yes | Trading pool to use: 'pumpfun' or 'pumpswap' |
slippage | number | No | Slippage tolerance in percent (default: 1) |
priorityFee | number | No | Priority fee in SOL (default: 0.0001) |
Response
{
"transaction": "base64EncodedSerializedTransaction"
}
Example
const axios = require('axios');
const web3 = require('@solana/web3.js');
async function buildAndSendTransaction() {
try {
// 1. Build the transaction using the PumpSwapApi API
const response = await axios.post('https://pumpswapapi.fun/api/trade/trade-local', {
publicKey: 'YOUR_WALLET_ADDRESS',
action: 'buy',
mint: '91WNez8D22NwBssQbkzjy4s2ipFrzpmn5hfvWVe2aY5p',
amount: '0.1',
amountType: 'sol',
pool: 'pumpfun',
slippage: 1,
priorityFee: 0.0001
});
const { transaction: serializedTransaction } = response.data;
// 2. Deserialize the transaction (for Versioned Transactions)
const transaction = web3.VersionedTransaction.deserialize(
Buffer.from(serializedTransaction, 'base64')
);
// 3. Connect to your preferred RPC endpoint
const connection = new web3.Connection('YOUR_RPC_ENDPOINT', 'confirmed');
// 4. Sign the transaction with your wallet
const wallet = web3.Keypair.fromSecretKey(YOUR_PRIVATE_KEY);
transaction.sign([wallet]);
// 5. Send the transaction
const signature = await connection.sendTransaction(transaction);
console.log('Transaction sent:', signature);
// 6. Wait for confirmation
await connection.confirmTransaction(signature, 'confirmed');
console.log('Transaction confirmed!');
} catch (error) {
console.error('Error:', error.message);
if (error.response) {
console.error('API Error:', error.response.data);
}
}
}
buildAndSendTransaction();
Selling Tokens - Using Percentage
When selling tokens, you can specify a percentage amount by including a '%' symbol:
// Sell 50% of your token balance
const response = await axios.post('https://pumpswapapi.fun/api/trade/trade-local', {
publicKey: 'YOUR_WALLET_ADDRESS',
action: 'sell',
mint: '91WNez8D22NwBssQbkzjy4s2ipFrzpmn5hfvWVe2aY5p',
amount: '50%',
amountType: 'token',
pool: 'pumpfun'
});
Possible Errors
Error Code | Message | Description |
---|---|---|
400 | Missing required parameters | One or more required parameters are missing |
400 | Sell action only supports token amounts | For 'sell' actions, amountType must be 'token' |
400 | Buy action only supports SOL amounts | For 'buy' actions, amountType must be 'sol' |
400 | Invalid amount value | Amount is not a valid number or percentage |
400 | Amount is too small. Minimum is 0.000001 SOL | Buy amount is below minimum |
400 | Amount is too small. Minimum is 1 token | Sell amount is below minimum |
400 | Unsupported trading pool | The specified pool is not valid |
400 | Invalid percentage value. Must be between 0 and 100 | For percentage sells, value must be 0-100 |
500 | Failed to process trade request | Generic server error |
Security Considerations
When using the PumpSwapApi Local Transaction API, you maintain control of your private keys at all times. The API only builds the transaction, which you then sign and send yourself. This provides an additional layer of security for sensitive operations.