Skip to content

jalbrekt85/pyrevm-contract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyrevm-contract

Contract wrapper for pyrevm

pip install pyrevm-contract

Quickstart

from pyrevm_contract import Revm, Contract

revm = Revm("https://eth.llamarpc.com", block_number="latest") # revm singleton; sets backend for all contracts

caller = "0x00000000000000000000000000000000000021E8"
weth_addr = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"

weth = Contract(weth_addr, abi_file_path="weth.json") # assuming a `weth.json` abi file

revm.set_balance(caller, 100) # revm cheatcode; sets ether balance of acct

weth.balanceOf(caller) # -> 0
weth.deposit(value=100, caller=caller) # provide tx level data with kwargs
weth.balanceOf(caller) # -> 100

Other ways to init contracts

via json file object:

weth_abi_path = ...
with open(weth_abi_path) as f:
    abi = json.load(f)

weth = Contract(weth_addr, abi)

define ABI manually:

from pyrevm_contract import ABIFunction, ContractABI

funcs = [
    ABIFunction(
        name="balanceOf",
        inputs=["address"],
        outputs=["uint256"],
        constant=True,
        payable=False,
    ),
    ABIFunction(
        selector="0xd0e30db0" # support for selector based funcs
        inputs=[],
        outputs=[],
        constant=False,
        payable=True
    )
]

weth = Contract(
    weth_addr,
    contract_abi=ContractABI(funcs),
)

automatic ABI resolution with heimdall:

coming soon

About

Minimal Brownie like contract wrapper for Pyrevm

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published