Skip to main content

evm-trace: Ethereum Virtual Machine transaction tracing tool

Project description

Quick Start

Ethereum Virtual Machine transaction tracing tool

Dependencies

  • python3 version 3.8 or greater, python3-dev

Installation

via pip

You can install the latest release via pip:

pip install evm-trace

via setuptools

You can clone the repository and use setuptools for the most up-to-date version:

git clone https://github.com/ApeWorX/evm-trace.git
cd evm-trace
python3 setup.py install

Quick Usage

Geth Style Traces

If you are using a node that supports the debug_traceTransaction RPC, you can use web3.py to get trace frames:

from web3 import HTTPProvider, Web3
from evm_trace import TraceFrame

web3 = Web3(HTTPProvider("https://path.to.my.node"))
struct_logs = web3.manager.request_blocking("debug_traceTransaction", [txn_hash]).structLogs
for item in struct_logs:
    yield TraceFrame(**item)

If you want to get the call-tree node, you can do:

from evm_trace import CallType, get_calltree_from_geth_trace

root_node_kwargs = {
    "gas_cost": 10000000,
    "gas_limit": 10000000000,
    "address": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
    "calldata": "0x00",
    "value": 1000,
    "call_type": CallType.CALL,
}

# Where `trace` is a `TraceFrame` (see example above)
calltree = get_calltree_from_geth_trace(trace, **root_node_kwargs)

Parity Style Traces

If you are using a node that supports the trace_transaction RPC, you can use web3.py to get trace objects:

from evm_trace import CallType, ParityTraceList

raw_trace_list = web3.manager.request_blocking("trace_transaction", [txn_hash])
trace_list = ParityTraceList.parse_obj(raw_trace_list)

And to make call-tree nodes, you can do:

from evm_trace import get_calltree_from_parity_trace

tree = get_calltree_from_parity_trace(trace_list)

Gas Reports

If you are using a node that supports creating traces, you can get a gas report.

from evm_trace.gas import get_gas_report

# see examples above for creating a calltree
calltree = get_calltree_from_geth_trace(trace, **root_node_kwargs)

gas_report = get_gas_report(calltree)

For a more custom report, use the merge_reports method to combine a list of reports into a single report. Pass two or more Dict[Any, Dict[Any, List[int]]] to combine reports where List[int] is the gas used.

Customize the values of Any accordingly:

  1. The first Any represents the bytes from the address.
  2. The second Any represents the method selector.

For example, you may replace addresses with token names or selector bytes with signature call strings.

Import the method like so:

from evm_trace.gas import merge_reports

Development

This project is in development and should be considered a beta. Things might not be in their final state and breaking changes may occur. Comments, questions, criticisms and pull requests are welcomed.

License

This project is licensed under the Apache 2.0.

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

evm-trace-0.1.0a14.tar.gz (40.9 kB view details)

Uploaded Source

Built Distribution

evm_trace-0.1.0a14-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file evm-trace-0.1.0a14.tar.gz.

File metadata

  • Download URL: evm-trace-0.1.0a14.tar.gz
  • Upload date:
  • Size: 40.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for evm-trace-0.1.0a14.tar.gz
Algorithm Hash digest
SHA256 0b2edf0040ff345d4f4025a8fa6d1afea2f705a28bb47dfd876d0b9d56d0e257
MD5 6efa074f56ba0050040ad218da6281ef
BLAKE2b-256 c7b7e95f254602d8bd8f1d3cfca3d5778fe797bd9a5fbc9b054299205d1e323f

See more details on using hashes here.

File details

Details for the file evm_trace-0.1.0a14-py3-none-any.whl.

File metadata

  • Download URL: evm_trace-0.1.0a14-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for evm_trace-0.1.0a14-py3-none-any.whl
Algorithm Hash digest
SHA256 8226c6d65572fc24b99dea81c00bfad422541be46fa8f59ab992142fe7ce07fc
MD5 bdd043fa8d82deb83aee258d812d4111
BLAKE2b-256 7cd44ad959eaed12b34cda8425e74ac57c925059b48063b3c63eeef76fe725f7

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