evm-trace: Ethereum Virtual Machine transaction tracing tool
Project description
evm-trace
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:
- The first
Any
represents the bytes from the address. - 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
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 evm-trace-0.1.0a8.tar.gz
.
File metadata
- Download URL: evm-trace-0.1.0a8.tar.gz
- Upload date:
- Size: 38.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 675db01caf9d87ce88f235f20d561a7998d3dd5510616fe25a07f510deba2b2a |
|
MD5 | 05578ecd33ceb582a098db60666339a8 |
|
BLAKE2b-256 | b271a9e8de12dd7f80a240a35c7c0813dbbe17208b0bea253cefe25f9585e2fe |
File details
Details for the file evm_trace-0.1.0a8-py3-none-any.whl
.
File metadata
- Download URL: evm_trace-0.1.0a8-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d7489612f96d49fbf520743733d953438124ee94d3ef0cd3cb4dc0ec595db67 |
|
MD5 | 878e2619405137cbafc93aaa0fde343d |
|
BLAKE2b-256 | 10200ef6874163d62800e6d99e59c7db81c50f1781e6f23688a629578a050c2b |