PumpPortal API

repository·main·Indexed 40 days ago

https://github.com/thetateman/trading-api

An unofficial API for interacting with the Pump.fun bonding curve, featuring a local trading endpoint for generating serialized transactions and Websockets for streaming real-time token creations and trade data.

Tokens
1.5K
Snippets
2
Records
3
Agent score
50%

What's inside PumpPortal

  1. Understand PumpPortal API fees

    main

    PumpPortal provides two types of APIs with different pricing models:

    1. Data API: Free to use (subject to rate limits). This includes the Websocket real-time updates.
    2. Trading API: Gated by an API key. A 0.5% fee is charged on each trade.

    Important Notes on Fees:

    • The 0.5% fee is calculated before slippage is applied, so the final fee amount may vary slightly from exactly 0.5% of the final trade value.
    • The fee does not include Solana network fees or any fees charged by the Pump.fun bonding curve itself.
  2. Use the PumpPortal Local Trading API to generate transactions

    main

    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();
  3. Stream real-time trading data via PumpPortal Websockets

    main

    Connect to the PumpPortal Websocket to receive real-time updates on token creations and trades.

    Websocket URL: wss://pumpportal.fun/api/data

    Once connected, send a JSON payload with a method to subscribe to specific streams:

    • subscribeNewToken: Receives events for new token creations.
    • subscribeTokenTrade: Receives all trades for specific token(s). Requires a keys array containing token contract addresses.
    • subscribeAccountTrade: Receives all trades made by specific account(s). Requires a keys array containing wallet addresses.
    import WebSocket from 'ws';
    
    const ws = new WebSocket('wss://pumpportal.fun/api/data');
    
    ws.on('open', function open() {
        // Subscribing to token creation events
        ws.send(JSON.stringify({
            method: "subscribeNewToken"
        }));
    
        // Subscribing to trades made by accounts
        ws.send(JSON.stringify({
            method: "subscribeAccountTrade",
            keys: ["AArPXm8JatJiuyEffuC1un2Sc835SULa4uQqDcaGpAjV"]
        }));
    
        // Subscribing to trades on tokens
        ws.send(JSON.stringify({
            method: "subscribeTokenTrade",
            keys: ["91WNez8D22NwBssQbkzjy4s2ipFrzpmn5hfvWVe2aY5p"]
        }));
    });
    
    ws.on('message', function message(data) {
        console.log(JSON.parse(data));
    });