solana-tx-decoder
v0.0.3
Published
[](https://www.npmjs.com/package/solana-tx-decoder) [](https://github.com/smallyun/solana-t
Readme
Solana Transaction Decoder
A robust, extensible TypeScript library for parsing Solana transactions into structured, human-readable data.
Features
- Adapter Pattern: Easily extensible parser registry.
- Universal IDL Resolver: Auto-decoding via Anchor IDLs (Skeleton).
- Structured Output: Strictly typed
ParsedResult. - Inner Instructions: Handles nested CPIs.
Installation
pnpm add solana-tx-decoder @solana/web3.js @coral-xyz/anchor decimal.jsUsage
import { Connection } from '@solana/web3.js';
import { SolanaParser } from 'solana-tx-decoder';
async function main() {
const connection = new Connection("https://api.mainnet-beta.solana.com");
const parser = new SolanaParser(connection);
const txId = "YOUR_TRANSACTION_SIGNATURE";
const result = await parser.parseTransaction(txId);
if (result) {
console.log("Success:", result.success);
console.log("Fee:", result.fee);
console.log("Actions:", JSON.stringify(result.actions, null, 2));
}
}
main();Extending Parsers
Implement the Parser interface and register it:
import { Parser, ParserContext, ParsedAction } from 'solana-tx-decoder/types';
class MyProtocolParser implements Parser {
programId = new PublicKey("MyProtocol11111111111111111111111111111111");
parse(context: ParserContext): ParsedAction | null {
// Custom decoding logic
return {
protocol: "MyProtocol",
type: "CustomAction",
summary: "Did something cool",
details: {}
};
}
}
parser.getRegistry().register(new MyProtocolParser());