@debridge-finance/solana-transaction-parser / SolanaParser
Class for parsing arbitrary solana transactions in various formats
- by txHash
- from raw transaction data (base64 encoded or buffer)
- @solana/web3.js getTransaction().message object
- @solana/web3.js getParsedTransaction().message or Transaction.compileMessage() object
- @solana/web3.js TransactionInstruction object
- addParser
- addParserFromIdl
- parseInstruction
- parseTransaction
- parseTransactionData
- parseTransactionDump
- parseTransactionParsedData
- removeParser
• new SolanaParser(programInfos
, parsers?
)
Initializes parser object
SystemProgram
, TokenProgram
and AssociatedTokenProgram
are supported by default
but may be overriden by providing custom idl/custom parser
Name | Type | Description |
---|---|---|
programInfos |
ProgramInfoType [] |
list of objects which contains programId and corresponding idl |
parsers? |
InstructionParserInfo [] |
list of pairs (programId, custom parser) |
▸ addParser(programId
, parser
): void
Adds (or updates) parser for provided programId
Name | Type | Description |
---|---|---|
programId |
PublicKey |
program id to add parser for |
parser |
ParserFunction <Idl , string > |
parser to parse programId instructions |
void
▸ addParserFromIdl(programId
, idl
): void
Adds (or updates) parser for provided programId
Name | Type | Description |
---|---|---|
programId |
string | PublicKey |
program id to add parser for |
idl |
Idl |
IDL that describes anchor program |
void
▸ parseInstruction<I
, IxName
>(instruction
): ParsedInstruction
<I
, IxName
>
Parses instruction
Name | Type |
---|---|
I |
extends Idl |
IxName |
extends string |
Name | Type | Description |
---|---|---|
instruction |
TransactionInstruction |
transaction instruction to parse |
ParsedInstruction
<I
, IxName
>
parsed transaction instruction or UnknownInstruction
▸ parseTransaction(connection
, txId
, flatten?
): Promise
<null
| ParsedInstruction
<Idl
, string
>[]>
Fetches tx from blockchain and parses it
Name | Type | Default value | Description |
---|---|---|---|
connection |
Connection |
undefined |
web3 Connection |
txId |
string |
undefined |
transaction id |
flatten |
boolean |
false |
true if CPI calls need to be parsed too |
Promise
<null
| ParsedInstruction
<Idl
, string
>[]>
list of parsed instructions
▸ parseTransactionData(txMessage
): ParsedInstruction
<Idl
, string
>[]
Parses transaction data
Name | Type | Description |
---|---|---|
txMessage |
Message |
message to parse |
ParsedInstruction
<Idl
, string
>[]
list of parsed instructions
▸ parseTransactionDump(txDump
): ParsedInstruction
<Idl
, string
>[]
Parses transaction dump
Name | Type | Description |
---|---|---|
txDump |
string | Buffer |
base64-encoded string or raw Buffer which contains tx dump |
ParsedInstruction
<Idl
, string
>[]
list of parsed instructions
▸ parseTransactionParsedData(txParsedMessage
): ParsedInstruction
<Idl
, string
>[]
Parses transaction data retrieved from Connection.getParsedTransaction
Name | Type | Description |
---|---|---|
txParsedMessage |
ParsedMessage |
message to parse |
ParsedInstruction
<Idl
, string
>[]
list of parsed instructions
▸ removeParser(programId
): void
Removes parser for provided program id
Name | Type | Description |
---|---|---|
programId |
PublicKey |
program id to remove parser for |
void