Skip to main content

Ethereum event decoder and topic generator

Project description

eth-event

Pypi Status Build Status Coverage Status

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_topic_map

# 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',
    'address': "0x3194cBDC3dbcd3E11a07892e7bA5c3394048Cc87",
    '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}
    ],
    'logIndex': 0,
    'blockNumber': 0,
    'transactionIndex': 0
}]

# 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, initial_address="0x3194cBDC3dbcd3E11a07892e7bA5c3394048Cc87")
[{
    'name': 'Transfer',
    'address': "0x3194cBDC3dbcd3E11a07892e7bA5c3394048Cc87",
    '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 decoded. In this case, the undecoded topic is returned and decoded is set to False.

  • Anonymous events cannot be decoded. Use the allow_undecoded kwarg when calling decode_logs and decode_trace to receive the undecoded log without raising an exception.

  • When decoding a trace, the initial address for the call cannot be determined. To include addresses where decoded events were emitted you must supply the initial address with the initial_address keyword argument.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eth-event-1.2.5.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

eth_event-1.2.5-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file eth-event-1.2.5.tar.gz.

File metadata

  • Download URL: eth-event-1.2.5.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for eth-event-1.2.5.tar.gz
Algorithm Hash digest
SHA256 b733447fbdefd35a3f3deeddb78eae9362246bcbfb19075952cc592803b29586
MD5 e173e2d30bb010ac79122e6fcf2715fa
BLAKE2b-256 40171c51069fe10af8d65fbca9bf31f2ee5c522ad1500784640634d4d766f5d9

See more details on using hashes here.

File details

Details for the file eth_event-1.2.5-py3-none-any.whl.

File metadata

  • Download URL: eth_event-1.2.5-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for eth_event-1.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 4572adf97d301b72061684ef0b252e659a9968d29705297a25eadc2784e636ac
MD5 39e1ad1f92a4afa691f604ca99d8bb24
BLAKE2b-256 ea27068e315649870ea5f7295b290fe214f2b0af1b5fce0604545b169c0773e9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page