Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

An open-source transaction parser for popular DeFi applications on the Solana blockchain 🚀🤖..

License

NotificationsYou must be signed in to change notification settings

Tee-py/solana-txn-parser

Repository files navigation

solana-transaction-parser

An open-source and lightweight transaction parser for popular DeFi applications on the Solana blockchain, written in TypeScript.

💪🏽 Supported DeFi Platforms

  • PumpFun ✅
  • RaydiumV4 ✅
  • Jupiter 🔜

👨‍🔧 Installation

npm i solana-parser

👨🏽‍💻 Usage

🎰 PumpFun Parser

import{PumpFunParser}from'solana-parser';import{Connection,PublicKey,clusterApiUrl,ParsedTransactionWithMeta}from'@solana/web3.js';importfsfrom"fs";constconnection=newConnection(clusterApiUrl('mainnet-beta'));constparser=newPumpFunParser();// Fetch a transactionconsttxnSig='<transaction_signature>'consttxn1=awaitconnection.getParsedTransaction(txnSig);// Parse single transactionconstpumpTxn=parser.parse(transaction);console.log(parsedTx);// Parse multiple transactionsconsttxnSig2='<second transaction signature>'consttxn2=awaitconnection.getParsedTransaction(txnSig2)constpumpTxns=parser.parseMultiple([txn1,txn2])// Parse transaction from json fileconsttxn=JSON.parse(fs.readFileSync("<file_path>","utf-8"))asunknownasParsedTransactionWithMetaconstpumpTxn=parser.parse(txn)

📦 Output Structure

The parser returns aPumpFunTransaction object (or an array ofPumpFunTransaction objects ifparseMultiple is called):

🎰 PumpFun Transaction Structure

ThePumpFunTransaction 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 thePumpFunAction interface as follows:

interfacePumpFunTransaction{platform:string;// pumpfunactions:PumpFunAction[];}

PumpFun Action Structure

ThePumpFunAction interface contains the three major actions that can occur in a PumpFun transaction (create,complete,trade), with theinfo field containing the relevant information for each action. The info field is of typeTradeInfo,CreateInfo, orCompleteInfo depending on the action.

interfacePumpFunAction{type:"create"|"complete"|"trade";info:TradeInfo|CreateInfo|CompleteInfo;}typeTradeInfo={solAmount:bigint;tokenAmount:bigint;tokenMint:PublicKey;trader:PublicKey;isBuy:boolean;timestamp:bigint;virtualSolReserves:bigint;virtualTokenReserves:bigint;};typeCreateInfo={name:string;symbol:string;uri:string;tokenMint:PublicKey;bondingCurve:PublicKey;tokenDecimals:number;createdBy:PublicKey;};typeCompleteInfo={user:PublicKey;tokenMint:PublicKey;bondingCurve:PublicKey;timestamp:bigint;};

🧑🏼‍🚀 RaydiumV4 Parser

import{RaydiumV4Parser}from'sol-parser/src';import{Connection,PublicKey,clusterApiUrl,ParsedTransactionWithMeta}from'@solana/web3.js';importfsfrom"fs";constconnection=newConnection(clusterApiUrl('mainnet-beta'));// set max size of lru cache for caching decoded pool infoconstparser=newRaydiumV4Parser(connection,{maxPoolCache:20});// Fetch a transactionconsttxnSig='<transaction_signature>'consttxn1=awaitconnection.getParsedTransaction(txnSig);// Parse single transactionconstresult=awaitparser.parse(transaction);console.log(result);// Parse multiple transactionsconsttxnSig2='<second transaction signature>'consttxn2=awaitconnection.getParsedTransaction(txnSig2)constresults=awaitparser.parseMultiple([txn1,txn2])// Parse transaction from json fileconsttxn=JSON.parse(fs.readFileSync("<file_path>","utf-8"))asunknownasParsedTransactionWithMetaconstresult=parser.parse(txn)

🔄 Jupiter Parser [Coming soon]

🧰 Creating Custom Parsers

You can create custom parsers for other DeFi platforms by extending theBaseParser class:

import{BaseParser,ParsedTransactionWithMeta}from'solana-txn-parser';// define action informationtypeActionInfo={// add neccessary fields for the action};// define your custom actioninterfaceCustomActionextendsBaseParsedAction{info:ActionInfo;}// define your custom transactioninterfaceCustomTransactionextendsBaseParsedTransaction<CustomAction>{actions:CustomAction[];}// define your parser classclassCustomParserextendsBaseParser<CustomTransaction>{parse(transaction:ParsedTransactionWithMeta):CustomTransaction{// Implement your parsing logic here}parseMultiple(transactions:ParsedTransactionWithMeta[]):CustomTransaction[]{returntransactions.map((tx)=>this.parse(tx));}}

NB: For anchor specific parsers that rely on events, you can use theanchorLogScanner function present in thesrc/core/utils file to get program events from the transaction.

🤝 Contributing

Here's how you can contribute to the library:

🎉 Adding a New Parser

  • Fork the repository and create a new branch for your parser.
  • Create a new folder in thesrc/parsers directory for your parser (e.g.,newparser).
  • Add an index.ts file in thesrc/parser/<newparser> directory to hold your Parser logic
  • Implement your parser by extending theBaseParser class.
  • Write unit tests for your parser in thetests/newparser directory.
  • Update the README.md to include documentation for your new parser.
  • Submit a pull request with your changes.

You can check the parser directory for more information on how to implement your new parser

♻️ Modifying/Improving Existing Parsers

  • Fork the repository and create a new branch for your modifications.
  • Make your changes to the existing parser file.
  • If you're adding new functionality, make sure to add corresponding unit tests.
  • If you're fixing a bug, add a test case that would have caught the bug.
  • Update the README.md if your changes affect the usage of the parser.
  • Submit a pull request with your changes, explaining the modifications and their purpose.

NB: For all contributions, please ensure your code passes all existing tests and include additional tests for the new parser. I also recommend using theanchorLogScanner function present in thesrc/core/utils file to get anchor program events from the transaction to avoid having to install anchor library (trying to make this library as lightweight as possible).

🗂️ License

This project is licensed under the MIT License - see theLICENSE file for details.

About

An open-source transaction parser for popular DeFi applications on the Solana blockchain 🚀🤖..

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp