To trade on the Pump.fun bonding curve while maintaining control over your private keys and RPC, use the trade-local endpoint. This endpoint returns a serialized transaction that you must sign locally using @solana/web3.js and then broadcast via your own RPC provider.
Endpoint: POST https://pumpportal.fun/api/trade-local
Request Body Parameters:
publicKey: Your wallet public key.action: Either "buy" or "sell".mint: The contract address (CA) of the token.amount: The amount of SOL or tokens to trade. For selling, you can use a percentage string like "100%".denominatedInSol: "true" if the amount is in SOL, "false" if it is in tokens.slippage: The percent slippage allowed.priorityFee: The amount to use as a priority fee.pool: (Optional) Either "pump" or "raydium". Defaults to "pump".
import { VersionedTransaction, Connection, Keypair } from '@solana/web3.js';
import bs58 from "bs58";
const RPC_ENDPOINT = "Your RPC Endpoint";
const web3Connection = new Connection(RPC_ENDPOINT, 'confirmed');
async function sendPortalTransaction() {
const response = await fetch(`https://pumpportal.fun/api/trade-local`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"publicKey": "your-public-key",
"action": "buy",
"mint": "token-ca-here",
"denominatedInSol": "false",
"amount": 1000,
"slippage": 1,
"priorityFee": 0.00001,
"pool": "pump"
})
});
if (response.status === 200) {
const data = await response.arrayBuffer();
const tx = VersionedTransaction.deserialize(new Uint8Array(data));
const signerKeyPair = Keypair.fromSecretKey(bs58.decode("your-wallet-private-key"));
tx.sign([signerKeyPair]);
const signature = await web3Connection.sendTransaction(tx);
console.log("Transaction: https://solscan.io/tx/" + signature);
} else {
console.log(response.statusText);
}
}
sendPortalTransaction();