
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
solana-parser
Advanced tools
lightweight transaction parser for popular DeFi applications on the Solana blockchain, written in TypeScript.
npm i solana-parser
import { PumpFunParser } from 'solana-parser';
import { Connection, PublicKey, clusterApiUrl, ParsedTransactionWithMeta } from '@solana/web3.js';
import fs from "fs";
const connection = new Connection(clusterApiUrl('mainnet-beta'));
const parser = new PumpFunParser();
// Fetch a transaction
const txnSig = '<transaction_signature>'
const txn1 = await connection.getParsedTransaction(txnSig);
// Parse single transaction
const pumpTxn = parser.parse(transaction);
console.log(parsedTx);
// Parse multiple transactions
const txnSig2 = '<second transaction signature>'
const txn2 = await connection.getParsedTransaction(txnSig2)
const pumpTxns = parser.parseMultiple([txn1, txn2])
// Parse transaction from json file
const txn = JSON.parse(fs.readFileSync("<file_path>", "utf-8")) as unknown as ParsedTransactionWithMeta
const pumpTxn = parser.parse(txn)
The parser returns a PumpFunTransaction object (or an array of PumpFunTransaction objects if parseMultiple is called):
The PumpFunTransaction object shows the different operations that occurred in the transaction. These operations are gotten from the events emitted during the transaction execution and are represented by the PumpFunAction interface as follows:
interface PumpFunTransaction {
platform: string; // pumpfun
actions: PumpFunAction[];
}
The PumpFunAction interface contains the three major actions that can occur in a PumpFun transaction (create, complete, trade), with the info field containing the relevant information for each action. The info field is of type TradeInfo, CreateInfo, or CompleteInfo depending on the action.
interface PumpFunAction {
type: "create" | "complete" | "trade";
info: TradeInfo | CreateInfo | CompleteInfo;
}
type TradeInfo = {
solAmount: bigint;
tokenAmount: bigint;
tokenMint: PublicKey;
trader: PublicKey;
isBuy: boolean;
timestamp: bigint;
virtualSolReserves: bigint;
virtualTokenReserves: bigint;
};
type CreateInfo = {
name: string;
symbol: string;
uri: string;
tokenMint: PublicKey;
bondingCurve: PublicKey;
tokenDecimals: number;
createdBy: PublicKey;
};
type CompleteInfo = {
user: PublicKey;
tokenMint: PublicKey;
bondingCurve: PublicKey;
timestamp: bigint;
};
import { RaydiumV4Parser } from 'sol-parser/src';
import { Connection, PublicKey, clusterApiUrl, ParsedTransactionWithMeta } from '@solana/web3.js';
import fs from "fs";
const connection = new Connection(clusterApiUrl('mainnet-beta'));
// set max size of lru cache for caching decoded pool info
const parser = new RaydiumV4Parser(connection, { maxPoolCache: 20 });
// Fetch a transaction
const txnSig = '<transaction_signature>'
const txn1 = await connection.getParsedTransaction(txnSig);
// Parse single transaction
const result = await parser.parse(transaction);
console.log(result);
// Parse multiple transactions
const txnSig2 = '<second transaction signature>'
const txn2 = await connection.getParsedTransaction(txnSig2)
const results = await parser.parseMultiple([txn1, txn2])
// Parse transaction from json file
const txn = JSON.parse(fs.readFileSync("<file_path>", "utf-8")) as unknown as ParsedTransactionWithMeta
const result = parser.parse(txn)
You can create custom parsers for other DeFi platforms by extending the BaseParser class:
import { BaseParser, ParsedTransactionWithMeta } from 'solana-txn-parser';
// define action information
type ActionInfo = {
// add neccessary fields for the action
};
// define your custom action
interface CustomAction extends BaseParsedAction {
info: ActionInfo;
}
// define your custom transaction
interface CustomTransaction extends BaseParsedTransaction<CustomAction> {
actions: CustomAction[];
}
// define your parser class
class CustomParser extends BaseParser<CustomTransaction> {
parse(transaction: ParsedTransactionWithMeta): CustomTransaction {
// Implement your parsing logic here
}
parseMultiple(transactions: ParsedTransactionWithMeta[]): CustomTransaction[] {
return transactions.map((tx) => this.parse(tx));
}
}
NB: For anchor specific parsers that rely on events, you can use the
anchorLogScannerfunction present in thesrc/core/utilsfile to get program events from the transaction.
Here's how you can contribute to the library:
src/parsers directory for your parser (e.g., newparser).src/parser/<newparser> directory to hold your Parser logicBaseParser class.tests/newparser directory.You can check the parser directory for more information on how to implement your new parser
NB: For all contributions, please ensure your code passes all existing tests and include additional tests for the new parser. I also recommend using the
anchorLogScannerfunction present in thesrc/core/utilsfile to get anchor program events from the transaction to avoid having to install anchor library (trying to make this library as lightweight as possible).
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
lightweight transaction parser for popular DeFi applications on the Solana blockchain, written in TypeScript.
The npm package solana-parser receives a total of 1 weekly downloads. As such, solana-parser popularity was classified as not popular.
We found that solana-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.