SolTool
Welcome
Fast Api
Local Api

Local Trade API Guide

This guide explains how to use the Local Transactions JSON-RPC API to get transaction instructions for local execution.

1. Get Trade Instruction

Use this method to get the transaction instruction for buying or selling tokens. This allows you to execute the transaction locally.

Request

{ "jsonrpc": "2.0", "id": 1, "method": "soltool_getTradeInstruction", "params": { "request": { "publicKey": "string", // Your wallet's public key "action": "Buy", // Action type (Buy or Sell) "mint": "string", // Token mint address "amount": "number", // Amount in SOL "slippage": "number", // Slippage tolerance in basis points "priorityFee": "number", // Priority fee in lamports "pool": "PumpFun" // Pool type } } }

Response

{ "jsonrpc": "2.0", "id": 1, "result": "string" // Base64 encoded transaction instruction }

Error Response Format

{ "jsonrpc": "2.0", "id": 1, "error": { "code": -32602, // Error code "message": "Invalid request", // Error message "data": "Detailed error information" // Optional detailed error information } }

Important Notes

1. Local Execution: These methods return transaction instructions that you can execute locally using your own Solana client.
2. Amount Format: All amounts are specified in lamports. For example, use 1000000 for 0.001 SOL.
3. Slippage: The default slippage is 1% (100 basis points). Adjust this based on your risk tolerance.
4. Priority Fees: Higher priority fees can help your transaction get processed faster during network congestion.
5. Pool Selection: Choose between PumpFun and PumpSwap pools based on your trading needs.

Best Practices

1. Transaction Verification:
- Always verify the transaction instruction before execution
- Check that all parameters match your intended transaction
- Verify the transaction accounts and program IDs

2. Error Handling:
- Handle network errors appropriately
- Implement retry logic for failed transactions
- Monitor transaction status after submission

3. Security:
- Keep your private keys secure
- Verify transaction signatures
- Use appropriate slippage tolerance

4. Performance:
- Monitor network conditions
- Adjust priority fees based on network congestion
- Consider using local RPC nodes for faster execution

Examples

import asyncio import base64 import httpx from solders.commitment_config import CommitmentLevel from solders.hash import Hash from solders.keypair import Keypair from solders.message import Message from solders.pubkey import Pubkey from solders.rpc.config import RpcContextConfig, RpcSendTransactionConfig from solders.rpc.requests import GetLatestBlockhash, SendVersionedTransaction from solders.system_program import TransferParams, transfer from solders.transaction import Transaction, VersionedTransaction async def buy_token_local(mint: Pubkey): async with httpx.AsyncClient() as client: try: # Get the create transaction instruction response = await client.post( "https://api.soltool.pro/rpc", json={ "jsonrpc": "2.0", "id": 1, "method": "soltool_getTradeInstruction", "params": { "request": { "publicKey": "<YOUR_PUBLIC_KEY>", "action": "Buy", "mint": str(mint), "amount": 1000000, "slippage": 100, # 1% "priorityFee": 1000, "pool": "PumpFun", } }, }, ) response.raise_for_status() result = response.json() if result.get("result", None) is not None: # Get transaction instruction decoded_data = base64.b64decode(result["result"]) # Create transaction signer_keypair = Keypair.from_base58_string("<YOUR_PRIVATE_KEY>") tx = VersionedTransaction( VersionedTransaction.from_bytes(decoded_data).message, [signer_keypair], ) # Send transaction commitment = CommitmentLevel.Confirmed config = RpcSendTransactionConfig(preflight_commitment=commitment) tx_payload = SendVersionedTransaction(tx, config) response = await client.post( url="https://api.mainnet-beta.solana.com/", headers={"Content-Type": "application/json"}, data=tx_payload.to_json(), ) response.raise_for_status() result = response.json() if "result" in result: tx_signature = result["result"] print(f"Transaction: https://solscan.io/tx/{tx_signature}") else: print( "Error:", result.get("error", {}).get("message", "Unknown error"), ) print( "Details:", result.get("error", {}).get("data", "Unknown error") ) else: print("Error:", result.get("error", {}).get("message", "Unknown error")) print("Details:", result.get("error", {}).get("data", "Unknown error")) except httpx.HTTPError as e: print(f"HTTP error occurred: {e}") except Exception as e: print(f"An error occurred: {e}")
Remember to:
- Replace `YOUR_SOLANA_RPC_ENDPOINT` with your Solana RPC endpoint
- Replace `your_public_key` with your wallet's public key
- Replace `your_private_key` with your wallet's private key
- Replace `token_mint_address` with the actual token mint address
- Adjust the amount, slippage, and priority fee according to your needs