πŸ“˜ How to Parse Solana Transactions (Pump.fun & PumpSwap) - cryptoking-max/solana-sniper-bot GitHub Wiki

Here's a sample GitHub Wiki page you can add to your repository to help others understand how to parse Solana transactions, especially for Pump.fun and PumpSwap.


πŸ“˜ How to Parse Solana Transactions (Pump.fun & PumpSwap)

This guide explains how to extract and decode useful data from Solana transactions, focusing specifically on transactions related to Pump.fun and PumpSwap.


πŸ”§ Prerequisites

To parse Solana transactions, you should:

  • Understand Solana's transaction format

  • Know how to work with binary buffers

  • Be familiar with decoding Base58 public keys

  • Use the following libraries:

npm install bs58

πŸ” Identifying Relevant Instructions

Each Solana transaction contains a set of:

  • instructions

  • innerInstructions

  • meta.logMessages

To isolate Pump.fun or PumpSwap-related activity, focus on innerInstructions and filter by the instruction data length or logMessages.


πŸš€ Example: tOutPut() Function

This function:

  • Extracts the transaction from webhook/event data

  • Flattens inner instructions

  • Locates the instruction with the largest data payload

  • Passes it to parseTransactionData() for decoding

export async function tOutPut(data) {
  const dataTx = data?.transaction?.transaction;
  if (!dataTx) return;

const meta = dataTx?.meta; const logs = meta?.logMessages; const innerInstructions = meta?.innerInstructions || [];

const allInstructions = innerInstructions.flatMap((ix) => ix.instructions || []); if (allInstructions.length === 0) return;

const largestDataInstruction = allInstructions.reduce((largest, current) => current.data.length > largest.data.length ? current : largest );

const parsedInstructionData = parseTransactionData(largestDataInstruction.data); if (!parsedInstructionData) return;

return { solChanges: parseFloat(parsedInstructionData.solchange), tokenChanges: parseFloat(parsedInstructionData.tokenchange), isBuy: parsedInstructionData.isBuy, user: parsedInstructionData.user, }; }


🧠 parseTransactionData(buffer)

This function parses raw instruction data based on expected structure:

βœ… PumpSwap Structure (320 bytes)

Fields include:

  • Base/Quote reserves

  • Pool/user addresses

  • LP fees, protocol fees

  • Actual quote received

if (buffer.length === 320) {
  // Parse relevant fields using offsets
  // e.g. baseAmountIn at offset 24, pool address at 128, user at 160
}

βœ… Pump.fun Structure (137 bytes)

Fields include:

  • Token Mint

  • Buy/Sell flag

  • Amount in SOL

  • Token amount

  • User, timestamp

  • Virtual & Real Reserves

if (buffer.length === 137) {
  // e.g. mint at offset 16, solAmount at 48, isBuy flag at 64
}

πŸ§ͺ Example Output

{
  "solChanges": "1.25",
  "tokenChanges": "985000000",
  "isBuy": true,
  "user": "6YyYx...Qsd8"
}

πŸ“Ž Utilities Used

Base58 Public Key Parser

function parsePublicKey(offset) {
  return bs58.encode(buffer.slice(offset, offset + 32));
}

BigInt Reader

function parseBigInt(offset) {
  return buffer.readBigUInt64LE(offset).toString();
}

πŸ›  Buffer Offsets Reference

Pump.fun Field Offset
Mint Address 16
SOL Amount 48
Token Amount 56
Buy/Sell Flag 64
User Address 65
Timestamp 97

🧯 Troubleshooting

  • Ensure the instruction buffer has the expected length (137 or 320 bytes).

  • If parsing fails, log buffer.length and hex output to identify changes.

  • Always check for null/undefined values in meta.innerInstructions.


🧬 Future Improvements

  • Add support for additional DEX transaction formats

  • Auto-detect instruction type from program ID

  • Handle compressed or modified Pump.fun contracts


Feel free to copy or adapt this into a file like docs/Parsing.md or create a GitHub Wiki page in your repo’s Wiki tab.

⚠️ **GitHub.com Fallback** ⚠️