Coder Social home page Coder Social logo

elyase / revm-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from davebryson/revm-python

0.0 1.0 0.0 180 KB

Python API for smart-contracts and revm

License: Apache License 2.0

Python 49.42% Rust 43.12% Makefile 1.22% Dockerfile 6.25%

revm-python's Introduction

revmup-python

A Python smart-contract API and blazingly fast (embedded) Ethereum Virtual Machine (EVM).

How is this different than Brownie, Ganache, Anvil?

  • It's only an EVM, no blocks or minings
  • No HTTP/JSON-RPC. You talk directly to the EVM (and it's fast)
  • Provides low-level access to storage
  • You can still do all the ethereum stuff: account transfers, contract interaction, etc...
  • Fork and interact with main chain historical data (coming soon...)

The primary motivation for this work was to be able to model smart-contract interaction in an Agent Based Modeling environment like Mesa. To do that, we needed a fast, flexible, EVM with a Python API.

Standing on the shoulders of giants

Thanks to the following projects for making this work easy!

Get Started

  • You need Rust, Python/Poetry. Will be available on PyPi soon.
  • Run make build
  • See revm_py/__init__.py for the main python api

Example

Deploy and interact with the classic counter smart contract

    # load contract abi
    with open("./tests/fixtures/counter.json") as f:
        counterabi = f.read()
    
    # create the EVM client
    client = Revm()

    # Create 2 accounts and fund them with 2 ether
    [deployer, alice] = client.create_accounts_with_balance(2, 2)

    # Create and instance of the contract and deploy it to the EVM
    counter = Contract(client, counterabi)
    address = counter.deploy(deployer)
    assert is_address(counter.address)

    # Contract functions are dynamically built from the ABI and
    # attached to the 'Contract.
    #
    # Call the 'setNumber' function from the contract
    # Alice is the 'from' address...setting the number to 10
    counter.setNumber(10, caller=alice)

    # Now call the 'number' function in the contract to 
    # check the state of the contract
    result = counter.number()
    assert result == 10

What's next

  • Mesa examples
  • Fork chain support

revm-python's People

Contributors

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