[Ethereum] Decoding transaction logs of Pancakeswap’s router by web3.py

bscscanetherscanlogspancakeswapweb3.py

I saw this question, but there are contracts like the pcs's router which have no event defined in the contract, see this transaction for example.

How can I decode the logs in such transactions?

Best Answer

You can fetch the logs related to transaction using Eth.get_transaction_receipt(tx_hash) . web3 should be connected into the network you are using, where the transaction is deployed.

>>> web3.eth.get_transaction_receipt('0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060')
AttributeDict({
    'blockHash': '0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1bdd',
    'blockNumber': 46147,
    'contractAddress': None,
    'cumulativeGasUsed': 21000,
    'from': '0xA1E4380A3B1f749673E270229993eE55F35663b4',
    'gasUsed': 21000,
    'logs': [],
    'logsBloom': '0x000000000000000000000000000000000000000000000000...0000',
    'status': 1, # 0 or 1
    'to': '0x5DF9B87991262F6BA471F09758CDE1c0FC1De734',
    'transactionHash': '0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060',
    'transactionIndex': 0, }) ```

From here you can fetch the logs, which should return transaction Receipt Event Logs corresponding to here.

>>> tx = web3.eth.get_transaction_receipt('0x4e07578a43f627e3a9fb2757cde7f796040868882229a35a68006a0b2aa5e21e')
>>> logs = tx["logs"]
Related Topic