question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(feature request?) parse transaction receipts for event log data output?

See original GitHub issue

How to extract event logged output?

Please have a look first how it is working in javascript/truffle:
logArgs.contractId
txLoggedArgs

I really want to work with Python and not JS - and apart from some minor hickups it is looking good.

But now, I need to get a specific value logArgs.contractId from an event log after a contract call, and I am stuck.
Because when I try the same as above with the py transaction receipts that I get via

rec = web3py.eth.getTransactionReceipt(tx)

then this of course fails:

logargs = rec.logs[0].args

with

 AttributeError: 'AttributeDict' object has no attribute 'args'

because it simply does not exist - and that seems different from javascript/truffle?

Is it because the event output args are still all mixed up in the rec.logs [0].topics field (or in the rec.logs [0].data field) ?

Example (complete receipt below).

'data': '0x00000000000000000000000000000000000000000000000000038d7ea4c68000ec099eeb7c6385269c410da8eb2e028bf832c8418d731bf99f987e9d9357abe9000000000000000000000000000000000000000000000000000000005a0c6ae0'
'topics': ['0xa0085ce7b3f5d49ff7ac7b4f8caaf2f75147d0228c3811a6d3d41eb2029fe122', '0xa4162351c79a5ed77bfc705394785c93842b6fc2e55d2b302c86ee55540c5b24', '0x000000000000000000000000c62d9f5092737fa7689579e279a3a1dd5543fb9e', '0x00000000000000000000000025f579697ce3fe1cf122fc5ffae9f1d83f16c676'],

Wouldn’t the ABI now help, to take those outputs apart?

Is there a helper function for that in web3py? which one?

If not, wouldn’t it be useful to have? Or … which external tool can I use now?

Or am I thinking this in a completely twisted way?
Is there a more direct way to access the answered contractId after a newContract call (solidity, abi) ?

because the web3.eth.contract(...).newContract(parameters, transact={...}) works well - but it returns only a a transaction hash. How does truffle actually manage it differently?

Thanks a lot.


{'blockHash': '0x9a120c06c6950f1a3fa29ebd2bfdd349652cda382087d3e402ccb0b56e87ac04',
 'blockNumber': 2076033,
 'contractAddress': None,
 'cumulativeGasUsed': 146500,
 'from': '0xc62d9f5092737fa7689579e279a3a1dd5543fb9e',
 'gasUsed': 146500,
 'logs': [AttributeDict({'removed': False, 'blockNumber': 2076033, 'logIndex': 0, 'data': '0x00000000000000000000000000000000000000000000000000038d7ea4c68000ec099eeb7c6385269c410da8eb2e028bf832c8418d731bf99f987e9d9357abe9000000000000000000000000000000000000000000000000000000005a0c6ae0', 'transactionIndex': 0, 'address': '0x131c7ba3ec8ebe69a6c58d084fd70adfacec76c5', 'topics': ['0xa0085ce7b3f5d49ff7ac7b4f8caaf2f75147d0228c3811a6d3d41eb2029fe122', '0xa4162351c79a5ed77bfc705394785c93842b6fc2e55d2b302c86ee55540c5b24', '0x000000000000000000000000c62d9f5092737fa7689579e279a3a1dd5543fb9e', '0x00000000000000000000000025f579697ce3fe1cf122fc5ffae9f1d83f16c676'], 'transactionHash': '0x3cffaa0926589452f9ead7eb016a8a63087051021beaab511fce366b5dcec3d8', 'blockHash': '0x9a120c06c6950f1a3fa29ebd2bfdd349652cda382087d3e402ccb0b56e87ac04'})],
 'logsBloom': '0x00000000000000000000000000000000000000000000002000000000000800400000000000000000000000000000000200000000080000400000000000000000000000000000000000000000000000000000002000200000000000000000000000000000000000000000000000000000020000000000000000000800000000000000000000000000000000000000100000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000010000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000',
 'status': '0x1',
 'to': '0x131c7ba3ec8ebe69a6c58d084fd70adfacec76c5',
 'transactionHash': '0x3cffaa0926589452f9ead7eb016a8a63087051021beaab511fce366b5dcec3d8',
 'transactionIndex': 0}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:22 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
carvercommented, Feb 21, 2018
1reaction
pipermerriamcommented, Nov 22, 2017

@drandreaskrueger glad to get this resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I parse the transaction receipt log with web3.js?
In this case, we're decoding log data that contains two variables, ... loop to handle all logs in this receipt. var log =...
Read more >
A Guide to Events and Logs in Ethereum Smart Contracts
A technical introduction to use cases for events and logs on the Ethereum blockchain with sample code.
Read more >
Ethereum data — Transaction Receipt Trie and Logs Simplified
Transaction receipt contains transaction outcomes (status and logs) and are organised in a trie structure. The receipt data resides in the state database ......
Read more >
How to read Event's log from transaction receipt with Web3.js?
I have implement function in my solidity project and it log some event with event name 'NewRound' that I want ...
Read more >
Examples — Web3.py 5.31.3 documentation - Read the Docs
Transaction receipts can be retrieved using the ... len(logs) == 1 # verify that the log's data matches the expected value event =...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found