DEV Community

Cover image for How to place a buy & sell trade on pump.fun tokens
Voren Tai
Voren Tai

Posted on

How to place a buy & sell trade on pump.fun tokens

Use this snippet to place the buy trade for a pumpfun token.

const axios = require('axios');

const url = "https://pumpapi.fun/api/trade";
const data = {
    trade_type: "sell",
    mint: "YOUR_MINT_ADDRESS",
    amount: 1000,  # Example amount of tokens
    slippage: 2,
    priorityFee: 500,  # Optional
    userPrivateKey: "WALLET_PRIVATEKEY"
};

axios.post(url, data)
  .then(response => {
    const transactionId = response.data.tx_hash;
    console.log(`Transaction ID: ${transactionId}`);
  })
  .catch(error => {
    console.error(error);
  });
Enter fullscreen mode Exit fullscreen mode

And to do the same using the python code:

import requests

url = "https://pumpapi.fun/api/trade"
payload = {
    "trade_type": "buy",                    # Buy or sell 
    "mint": "YOUR_MINT_ADDRESS",            # Token mint address
    "amount": 0.01,                         # Amount in SOL , if buying or of tokens if selling.
    "slippage": 5,                          # Desired slippage 
    "priorityFee": 0.003,                   # Value in SOL
    "userPrivateKey: "WALLET_PRIVATEKEY"   # Wallet private key 
}

response = requests.post(url, json=payload)

if response.status_code == 200:
    transaction_id = response.json()["tx_hash"]
    print(f"Transaction ID: {transaction_id}")
else:
    print(f"Error: {response.status_code} - {response.text}")

Enter fullscreen mode Exit fullscreen mode

Endpoints:

API provides various endpoints for interacting with Pump.fun, including:

Feature Description
Buy & Sell Trades Place trades on Pump.fun programmatically
Newer Mints Details Get details on new mints on Pump.fun
Token Metadata Fetching Fetch metadata for tokens on Pump.fun
Pump.fun Specific Data Query data specific to Pump.fun
Swap Quotes Fetch swap quotes and input/output details

Read more on API documentation to learn how to use these features. 📄

API Endpoint 📍

Our API endpoint is:

https://pumpapi.fun/api

Happy Hacking 💻

Top comments (1)

Collapse
 
nationz_5048a0247d5a8d8da profile image
Nationz

The API documentation is at:

docs.pumpapi.fun