Skip to main content

evm-trace: Ethereum Virtual Machine transaction tracing tool

Project description

evm-trace

Ethereum Virtual Machine transaction tracing tool

Dependencies

  • python3 version 3.7.2 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)

Call Tree Node Customization

You can also customize the output by making your own display class:

from evm_trace.display import DisplayableCallTreeNode, get_calltree_from_trace


class CustomDisplay(DisplayableCallTreeNode):
    def title(self) -> str:
        call_type = self.call.call_type.value.lower().capitalize()
        address = self.call.address.hex()
        cost = self.call.gas_cost
        return f"{call_type} call @ {address} gas_cost={cost}"


calltree = get_calltree_from_geth_trace(trace, display_cls=CustomDisplay)

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.0a5.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

evm_trace-0.1.0a5-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: evm-trace-0.1.0a5.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.12

File hashes

Hashes for evm-trace-0.1.0a5.tar.gz
Algorithm Hash digest
SHA256 a580588716693f074af931f4a26394fbe87e981e0872678f28f1beccfd2d281e
MD5 6c24a1411b2d46286f5c95bab4699404
BLAKE2b-256 cebd6ef3f12e2a16b8e8442b2bfd871c26ac1cc14ffe14dd323a4b30394da833

See more details on using hashes here.

File details

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

File metadata

  • Download URL: evm_trace-0.1.0a5-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.12

File hashes

Hashes for evm_trace-0.1.0a5-py3-none-any.whl
Algorithm Hash digest
SHA256 2ae0c646ef3c0db88395a79678ec6489c7c06d8a736eb0cf1a7035b7403f3b41
MD5 05c674b3e23bee47133cc8f4c93315ad
BLAKE2b-256 135d518c483fa8add9d6baf72eeb90b662d16f0dca82b1eab47b562de7b9eccd

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