• Non-custodial API
  • Trade Token

Trade Token

To get a transaction for signing and sending, you need to make a POST request to the REST API entry point

https://pumpzone.fun/api/v2/trade


Include a JSON payload in the body of your request:

  • pub_key — Your wallet public key (base58)
  • mint — Token addressа (base58)
  • action — «buy» or «sell»
  • amount_sol — The amount of SOL to buy a token. It's mutually exclusive with the amount_tokens field
  • amount_percent — The amount of tokens to sell in percent. It's mutually exclusive with the amount_tokens field
  • amount_tokens — The amount of tokens to buy/sell
  • slippage — The percent slippage allowed in percent (by default 25%)
  • priority_fee — Amount used to enhance transaction speed

Examples

import requests

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

user_keypair = Keypair.from_base58_string('Your base58 private key here')

res = requests.post('https://pumpzone.fun/api/v2/trade',
    headers = {"Content-Type": "application/json"},
    json = {
        'pub_key'       : str(user_keypair.pubkey()),                       # Your wallet address
        'mint'          : '6WsLDhrc3hURPx5Rn3e12rBoRiXnj4F13K27uVn6stMF',   # Token address
        'action'        : 'sell',                                           # 'buy' or 'sell'
        'amount_tokens' : 10**6,                                            # The amount of tokens to sell
        # 'amount_percent' : 30,                                            # or a percentage of tokens
        'slippage'      : 25,                                               # The percent slippage allowed (1 .. 100)
        'priority_fee'  : 0.0005,                                           # Amount to use as priority fee
})

if res.status_code != 200:
    print(res.text)
    exit()

response = res.json()
message  = from_bytes_versioned(bytes(response['result']['message']))

RPC_ENTRYPOINT = 'https://api.mainnet-beta.solana.com'  # Your RPC entrypoint
res = requests.post(RPC_ENTRYPOINT,
    headers={"Content-Type": "application/json"},
    data = SendVersionedTransaction(
        tx      = VersionedTransaction(message = message, keypairs = [user_keypair]),
        config  = RpcSendTransactionConfig(preflight_commitment = CommitmentLevel.Confirmed)
    ).to_json()
)

if res.status_code == 200:
    signature = res.json()['result']
    print(signature)
import { VersionedTransaction, Connection, Keypair, MessageV0 } from '@solana/web3.js';
import axios from 'axios';

const RPC_ENDPOINT = "https://api.mainnet-beta.solana.com"; // Your RPC entrypoint
const rpc_client = new Connection(
    RPC_ENDPOINT,
    'confirmed',
);

async function noncustodial_trade() {
   const user_keypair = Keypair.fromSecretKey(bs58.decode('Your base58 private key here'));

   const res = await axios.post('https://pumpzone.fun/api/v2/trade',
      JSON.stringify({
         pub_key       : user_keypair.publicKey.toString(),                // Your wallet address
         mint          : '6WsLDhrc3hURPx5Rn3e12rBoRiXnj4F13K27uVn6stMF',   // Token address
         action        : 'sell',                                           // 'buy' or 'sell'
         amount_tokens : 10**6,                                            // The amount of tokens to sell
         // amount_percent : 30,                                           // or a percentage of tokens
         slippage      : 25,                                               // The percent slippage allowed (1 .. 100)
         priority_fee  : 0.0005,                                           // Amount to use as priority fee
      }),
      {headers: { 'Content-Type': 'application/json' }}
   );

   if(res.status != 200) {
      console.log(res.data);
      return;
   }

   const message = MessageV0.deserialize(new Uint8Array(res.data.result.message));
   const tx = new VersionedTransaction(message);
   tx.sign([user_keypair]);

   const signature = await rpc_client.sendTransaction(tx);
   console.log(signature);
}
# status_code == 200
{
  "version" : "v2",
  "result"  : {
    "mint"    : "6WsLDhrc3hURPx5Rn3e12rBoRiXnj4F13K27uVn6stMF   ",
    "message" : [ byte array... ],
  }
}

# status_code != 200
{
  "version" : "v2",
  "errors"  : [ "Internal error, service is unavailable at now moment" ]
}