Skip to content

feat: add trx.parseTransaction() and trx.parseTransactionLogs()#699

Open
0xyoshii wants to merge 2 commits intotronprotocol:masterfrom
0xyoshii:feature/transaction-decoder
Open

feat: add trx.parseTransaction() and trx.parseTransactionLogs()#699
0xyoshii wants to merge 2 commits intotronprotocol:masterfrom
0xyoshii:feature/transaction-decoder

Conversation

@0xyoshii
Copy link
Copy Markdown

Exposes TronWeb's existing hidden Interface class and adds high-level
trx.parseTransaction() / trx.parseTransactionLogs() methods, bringing
ethers.js equivalent transaction decoding to TronWeb with TRON-specific
address conversion.

The problem: TronWeb has an Interface class (adapted from ethers.js)
in src/utils/interface.ts with parseTransaction(), parseLog(), and
parseError() — but these are not exported, not documented, and only used
internally for function selector generation. Developers must manually extract
4-byte selectors, look up function signatures, call decodeParams() with
hand-specified types, and convert every address from hex to base58.

The solution:

  • Export Interface, LogDescription, TransactionDescription, ErrorDescription
    as public API via tronWeb.utils.ethersUtils
  • Add tronWeb.trx.parseTransaction(txIdOrData, abi?), parses smart contract
    calldata with auto ABI fetch and hex→base58 address conversion
  • Add tronWeb.trx.parseTransactionLogs(txId, abi?), decodes event logs from
    transaction receipts
  • Add ParsedTransaction and ParsedLog TypeScript types

Before (manual, ~15 lines)

const tx = await tronWeb.trx.getTransaction(txId);                                                                   
const data = tx.raw_data.contract[0].parameter.value.data;
const selector = data.slice(0, 8);                                                                                   
// manually look up function, specify types, decode, convert addresses...

After (one line)

const parsed = await tronWeb.trx.parseTransaction(txId);                                                             
// parsed.args.to is already in base58 format  

Test plan

  • 14 unit tests for Interface class (parseTransaction, parseLog, parseError, roundtrip, selectors)
  • 10 unit tests for trx.parseTransaction (TRC-20 transfer/approve, SunSwap V2 swap, addLiquidity, tuple params, error
    handling)
  • 7,858 existing tests still passing (zero regressions)
  • Manual verification on Nile testnet with real SunSwap transactions

…uman-readable transaction

  decoding

  - Export the existing Interface class (parseTransaction, parseLog, parseError) as a public API
  - Add high-level trx.parseTransaction() with auto ABI fetch and hex-to-base58 address conversion
  - Add trx.parseTransactionLogs() for decoding event logs from transaction receipts
  - Add ParsedTransaction and ParsedLog types
  - 24 new unit tests covering TRC-20 transfers, SunSwap V2 swaps, tuple params, error cases
  - Documentation with before/after examples in README
@0xyoshii 0xyoshii force-pushed the feature/transaction-decoder branch from 9159df2 to 3a8cb5a Compare March 28, 2026 00:06
  - On-chain ABIs use capitalized types (Function, Event) but Interface expects lowercase
  - Add demo/demo.js showcasing old way vs new way with real mainnet SunSwap tx
  - Add docs/transaction-decoder.md with full API reference
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant