Ethereum event decoder and topic generator
Project description
eth-event
Tools for Ethereum event decoding and topic generation.
Installation
You can install the latest release via pip
:
pip install eth-event
Or clone the repository and use setuptools
for the most up-to-date version:
git clone https://github.com/iamdefinitelyahuman/eth-event.git
cd eth-event
python3 setup.py install
Usage
The public API is well documented within the docstrings. The following example may also help:
>>> from eth_event import get_topics
# generating a topic map
>>> abi = open('abi.json').read()
>>> topic_map = get_topic_map(abi)
>>> topic_map
{
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef': {
'name': 'Transfer',
'inputs': [
{'name': 'from', 'type': 'address', 'indexed': True},
{'name': 'to', 'type': 'address', 'indexed': True},
{'name': 'value', 'type': 'uint256', 'indexed': False}
]
}
}
# decoding event logs from a transaction receipt
>>> tx = token.transfer(account[1], 100, {'from': account[0]})
<Transaction object '0x615a157e84715d5f960a38fe2a3ddb566c8393cfc71f15b06170a0eff74dfdde'>
>>> eth_event.decode_logs(tx.logs, topic_map)
[{
'name': 'Transfer',
'data': [
{'name': 'from', 'type': 'address', 'value': '0xbd4940951bfa463f8fb6db762e55686f6cfdb73a', 'decoded': True},
{'name': 'to', 'type': 'address', 'value': '0xbd4940951bfa463f8fb6db762e55686f6cfdb73a', 'decoded': True},
{'name': 'tokens', 'type': 'uint256', 'value': 100, 'decoded': True}
]
}]
# decoding a structLog from Geth's debug_traceTransaction endpoint
>>> trace = web3.provider.make_request(
"debug_traceTransaction",
['0x615a157e84715d5f960a38fe2a3ddb566c8393cfc71f15b06170a0eff74dfdde', {}]
)
>>> struct_log = trace['result']['structLogs']
>>> eth_event.decode_trace(struct_log, topic_map)
[{
'name': 'Transfer',
'data': [
{'name': 'from', 'type': 'address', 'value': '0xbd4940951bfa463f8fb6db762e55686f6cfdb73a', 'decoded': True},
{'name': 'to', 'type': 'address', 'value': '0xbd4940951bfa463f8fb6db762e55686f6cfdb73a', 'decoded': True},
{'name': 'tokens', 'type': 'uint256', 'value': 100, 'decoded': True}
]
}]
Limitations
-
If an array is indexed in an event, the topic is generated as a sha3 hash and so cannot be decrypted. In this case, the unencrypted topic is returned and
decoded
is set toFalse
. -
Anonymous events cannot be decoded. Use the
allow_undecoded
kwarg when callingdecode_logs
anddecode_trace
to receive the undecoded log without raising an exception.
Tests
To run the test suite:
$ tox
Development
This project is still in development. Comments, questions, criticisms and pull requests are welcomed.
License
This project is licensed under the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file eth-event-1.0.0.tar.gz
.
File metadata
- Download URL: eth-event-1.0.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3b258acdf9585a7b0800b06ef2f4732df70cc8522d494e050ca972b7b0b746a |
|
MD5 | 54c258b4a6562fc59fe7ab8ca563e683 |
|
BLAKE2b-256 | 767c821a34eb6d3b1c626c9b96ddd2320d2f712610a47bef5f3f4645325d660c |
File details
Details for the file eth_event-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: eth_event-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 313527e94e7ee43ef51f9b647582e0c159c15bd2fe621491c063a4d44f856cc4 |
|
MD5 | bba54da28b0ba81643952e9d35076b62 |
|
BLAKE2b-256 | 066bfcfeee8300fa3340fe59ececf8e1d437b88d1730b5c808894ae3fed9d58e |