GithubHelp home page GithubHelp logo

banteg / evm-trace Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apeworx/evm-trace

5.0 1.0 2.0 281 KB

Ethereum Virtual Machine transaction tracing tool

License: Apache License 2.0

Python 100.00%

evm-trace's Introduction

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

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_trace

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

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

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_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.

evm-trace's People

Contributors

antazoey avatar notpeopling2day avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.