• Stars
    star
    298
  • Rank 139,663 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 2 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ethereum Virtual Machine transaction tracing tool

Quick Start

Ethereum Virtual Machine transaction tracing tool

Dependencies

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"))
txn_hash = "0x..."
struct_logs = web3.manager.request_blocking("debug_traceTransaction", [txn_hash]).structLogs
for item in struct_logs:
    frame = TraceFrame.parse_obj(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.

More Repositories

1

ape

The smart contract development tool for Pythonistas, Data Scientists, and Security Professionals
Python
855
star
2

py-solc-x

Python wrapper and version management tool for the solc Solidity compiler.
Python
138
star
3

silverback

Blockchain automation library, and SDK for the (upcoming) Silverback Platform
Python
79
star
4

eip712

Message classes for typed structured data hashing and signing in Ethereum
Python
41
star
5

ape-foundry

Foundry network provider for the Ape Framework
Python
32
star
6

py-tokenlists

Uniswap Token Lists implementation in Python.
Python
32
star
7

ape-vyper

Vyper compiler plugin for the Ape Framework, using VVM
Python
26
star
8

ape-etherscan

Etherscan explorer plugin using EVM-based networks for the Ape Framework
Python
23
star
9

evm-asm

EVM Opcodes, Assembler, and Disassembler
Python
23
star
10

project-template

Plugin project template for the Ape Framework
Python
23
star
11

ape-alchemy

Alchemy network provider plugin for the Ape Framework
Python
19
star
12

ape-hardhat

Hardhat network provider for the Ape Framework
Python
18
star
13

ApePay

A smart contract payment system built for automated service management
TypeScript
18
star
14

archive-ape-starknet

StarkNet ecosystem plugin for the Ape Framework
Python
18
star
15

ape-notebook

Launch a Jupyter Notebook using the Ape Framework
Python
17
star
16

ape-solidity

Solidity compiler plugin for the Ape Framework
Python
15
star
17

ethpm-types

Implementation of EIP-2678
Python
14
star
18

ape-safe

Safe (Wallet) account plugin for the Ape Framework
Python
13
star
19

ape-template

Plugin for working with Cookiecutter-based project templates
Python
11
star
20

ape-arbitrum

Arbitrum ecosystem plugin for the Ape Framework
Python
9
star
21

ape-optimism

Optimism network provider plugin for the Ape Framework
Python
9
star
22

ape-tokens

Tokens converter plugin for the Ape Framework
Python
9
star
23

ape-infura

Infura network provider plugin for the Ape Framework
Python
8
star
24

archive-ape-cairo

Cairo programming language compiler plugin for the Ape Framework
Python
8
star
25

uniswap-sdk

Ape SDK for Uniswap v2 & v3
Python
7
star
26

ape-addressbook

Address converter plugin: tracking addresses and contracts in projects globally
Python
7
star
27

ape-ledger

Ledger Nano S and X account plugin for the Ape Framework
Python
6
star
28

github-action

GitHub Actions CI File for Ape Projects
6
star
29

walletconnect-py

WalletConnect implementation in Python
Python
5
star
30

ape-polygon

Polygon ecosystem plugin for the Ape Framework
Python
5
star
31

ape-ganache

Ganache network provider plugin for the Ape Framework
Python
4
star
32

ape-frame

Frame (https://frame.sh) account plugin for the Ape Framework
Python
4
star
33

ape-trezor

Trezor Hardware Wallet account plugin for the Ape Framework
Python
4
star
34

ape-fantom

Fantom ecosystem plugin for the Ape Framework
Python
4
star
35

hosted-compiler

Compiler tool supporting Remix Online IDE
Python
4
star
36

ape-flashbots

Web3 Flashbots network provider plugin for the Ape Framework
Python
3
star
37

ape-chainstack

Chainstack network provider plugin for the Ape Framework
Python
3
star
38

faucet

Self-hosted faucet web app for public and private testnets
Python
3
star
39

ape-titanoboa

Titanoboa integration and pytest runner (experimental)
Python
3
star
40

ape-tenderly

Tenderly network provider plugin for the Ape Framework
Python
3
star
41

taskiq-sqs

SQS Broker for TaskIQ
Python
3
star
42

apegenius

Telegram bot that answers questions by sourcing answers from docs and codebases
JavaScript
3
star
43

eth-pydantic-types

ETH Pydantic types
Python
3
star
44

apeworx.github.io

Docs Homepage
JavaScript
2
star
45

bridge_prototype

Example project for using a network bridge in Ape
Python
2
star
46

ape-ens

Ethereum Name Service (ENS) converter plugin for the Ape Framework
Python
2
star
47

ape-cairo

Rust
2
star
48

simple-nft

Vyper
2
star
49

ape-polygon-zkevm

Polygon-ZkEVM ecosystem plugin for the Ape Framework
Python
2
star
50

ape-aws

Plugin to interact with AWS for transactions on the Ethereum Blockchain
Python
2
star
51

node-utils

Python
1
star
52

Flask-WalletConnect

Flask plugin that allows integrating with a user's wallet over WalletConnect
Python
1
star
53

ape-base

Base ecosystem plugin for the Ape Framework
Python
1
star
54

evmchains

Provides general metadata on EVM-compatible chains organized by Ape-style ecosystem and network.
Python
1
star
55

ape-bsc

Binance Smart Chain (BSC) Ecosystem Plugin
Python
1
star
56

SafeDrop

A convenient way to disburse whitehat funds
1
star