feat: add trx.parseTransaction() and trx.parseTransactionLogs()#699
Open
0xyoshii wants to merge 2 commits intotronprotocol:masterfrom
Open
feat: add trx.parseTransaction() and trx.parseTransactionLogs()#6990xyoshii wants to merge 2 commits intotronprotocol:masterfrom
0xyoshii wants to merge 2 commits intotronprotocol:masterfrom
Conversation
…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
9159df2 to
3a8cb5a
Compare
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Exposes TronWeb's existing hidden
Interfaceclass and adds high-leveltrx.parseTransaction()/trx.parseTransactionLogs()methods, bringingethers.js equivalent transaction decoding to TronWeb with TRON-specific
address conversion.
The problem: TronWeb has an
Interfaceclass (adapted from ethers.js)in
src/utils/interface.tswithparseTransaction(),parseLog(), andparseError()— but these are not exported, not documented, and only usedinternally for function selector generation. Developers must manually extract
4-byte selectors, look up function signatures, call
decodeParams()withhand-specified types, and convert every address from hex to base58.
The solution:
Interface,LogDescription,TransactionDescription,ErrorDescriptionas public API via
tronWeb.utils.ethersUtilstronWeb.trx.parseTransaction(txIdOrData, abi?), parses smart contractcalldata with auto ABI fetch and hex→base58 address conversion
tronWeb.trx.parseTransactionLogs(txId, abi?), decodes event logs fromtransaction receipts
ParsedTransactionandParsedLogTypeScript typesBefore (manual, ~15 lines)
After (one line)
Test plan
handling)