Skip to main content

Buy and Sell – API

Use this to buy and sell tokens.
Supported pools

  • Pump.fun
  • LetsBonk.fun
  • Raydium LaunchPad
  • PumpSwap
  • Raydium CPMM

Endpoint

POST https://api.pumpapi.io

Request Body

FieldDescription
publicKeyYour public key (the wallet address)
action"buy" or "sell"
mintMint address of the token
amountAmount to trade. Use '100%' to sell all and get a 0.002 sol refund from the network
denominatedInSol"true" if amount is in SOL, "false" for token amount
slippageSlippage in percent (recommended: 20)
priorityFeeOptional priority fee in SOL

import requests
from solders.transaction import VersionedTransaction
from solders.keypair import Keypair
from solders.commitment_config import CommitmentLevel
from solders.rpc.requests import SendVersionedTransaction
from solders.rpc.config import RpcSendTransactionConfig

response = requests.post(url="https://api.pumpapi.io", data={
"publicKey": "your_public_key",
"action": "buy", # or sell
"mint": "token_address",
"amount": 0.01,
"denominatedInSol": "true",
"slippage": 20,
"priorityFee": 0.0001,
})

keypair = Keypair.from_base58_string("your_private_key")
tx = VersionedTransaction(VersionedTransaction.from_bytes(response.content).message, [keypair])

commitment = CommitmentLevel.Confirmed
config = RpcSendTransactionConfig(preflight_commitment=commitment)
txPayload = SendVersionedTransaction(tx, config)

response = requests.post(
url="https://api.mainnet-beta.solana.com/", # it's better to use Helius RPC endpoint
headers={"Content-Type": "application/json"},
data=SendVersionedTransaction(tx, config).to_json()
)
txSignature = response.json()['result']
print(f'Transaction: https://solscan.io/tx/{txSignature}')
tip

Want cleaner code and faster execution? Use our ⚡ Lightning transactions


Need help? Join our Telegram group.