Buy API
The Buy API endpoint executes a token purchase on the Solana blockchain. It calculates the necessary transaction amounts, applies a custom priority fee, ensures token accounts are created if required, signs the transaction, and returns the transaction signature.
Endpoint Details
- Method:
POST
- URL:
https://api.pumpfunapis.com/api/buy
Request Body
Example Request Body
{
"private_key": "PRIVATE_KEY", // Please use a BURNER trading wallet
"mint": "Token_CA", // Mint Address
"sol_in": 1.0, // Amount in SOL (e.g., 1.0 SOL)
"slippage": 25, // Default Slippage (percentage, e.g., 25 for 25%)
"priorityFee": 0.002, // Priority fee in SOL (e.g., 0.002 SOL)
"rpc": null // Custom RPC endpoint, leave blank for default
}
Example Usage
Curl Example
cURL Example
curl --location --request POST 'https://api.pumpfunapis.com/api/buy' \
--header 'Content-Type: application/json' \
--data-raw '{
"private_key": "PRIVATE_KEY",
"mint": "Token_CA",
"sol_in": 1.0,
"slippage": 25,
"priorityFee": 0.002,
"rpc": null
}'
Python Example
Python Example
import requests
def buy_token():
url = "https://api.pumpfunapis.com/api/buy"
payload = {
"private_key": "PRIVATE_KEY",
"mint": "Token_CA",
"sol_in": 1.0,
"slippage": 25,
"priorityFee": 0.002,
"rpc": None
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
print("Transaction Signature:", response.json().get("tx_signature"))
else:
print("Failed to execute buy transaction:", response.text)
buy_token()
JavaScript Example
JavaScript Example
const fetch = require('node-fetch');
const buyToken = async () => {
const response = await fetch('https://api.pumpfunapis.com/api/buy', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
private_key: 'PRIVATE_KEY',
mint: 'Token_CA',
sol_in: 1.0,
slippage: 25,
priorityFee: 0.002,
rpc: null,
}),
});
if (!response.ok) {
throw new Error('Failed to execute buy transaction');
}
const data = await response.json();
console.log('Transaction Signature:', data.tx_signature);
};
buyToken().catch(console.error);
Response
Successful Response
200 OK
{
"status": "success",
"tx_signature": "5ba4sCas...."
}
Notes
- Ensure that the
private_key
used is from a secure burner wallet. - Use appropriate slippage settings to avoid failed transactions.