{"id":10128,"library":"pyrevm","title":"pyrevm: Python bindings for revm EVM","description":"pyrevm provides Python bindings to revm, a high-performance Ethereum Virtual Machine (EVM) written in Rust. It enables Python developers to simulate Ethereum transactions, execute smart contracts, and interact with the EVM environment directly from Python, offering a fast and efficient way to prototype and test EVM-based logic. The current version is 0.3.7, and the project maintains an active development cadence, often mirroring the underlying revm library's updates.","status":"active","version":"0.3.7","language":"en","source_language":"en","source_url":"https://github.com/paradigmxyz/pyrevm","tags":["ethereum","evm","blockchain","virtual-machine","simulation"],"install":[{"cmd":"pip install pyrevm","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"EVM","correct":"from pyrevm import EVM"},{"symbol":"CfgEnv","correct":"from pyrevm import CfgEnv"},{"symbol":"BlockEnv","correct":"from pyrevm import BlockEnv"},{"symbol":"TxEnv","correct":"from pyrevm import TxEnv"}],"quickstart":{"code":"from pyrevm import EVM, CfgEnv, BlockEnv, TxEnv\n\n# Example setup: a simple contract and an account\n# Contract that returns 0 for a specific function call\nCONTRACT_CODE = bytes.fromhex(\"6080604052348015600f57600080fd5b506004361060285760003560e01c806306fdde0314602d575b600080fd5b603a603c565b005b60005481565b\")\nCONTRACT_ADDRESS = bytes.fromhex(\"1234567890123456789012345678901234567890\")\nCALLER_ADDRESS = bytes.fromhex(\"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\")\n\n# Function selector for the example contract (returns 0)\nFUNCTION_SELECTOR = bytes.fromhex(\"06fdde03\")\n\ndef run_evm_simulation():\n    # 1. Initialize environment configurations\n    cfg_env = CfgEnv(chain_id=1)\n    block_env = BlockEnv(\n        number=1, timestamp=1, gas_limit=1_000_000_000,\n        miner=bytes.fromhex(\"0000000000000000000000000000000000000000\"), basefee=1\n    )\n    tx_env = TxEnv(\n        caller=CALLER_ADDRESS, gas_limit=1_000_000_000, gas_price=1, value=0,\n        data=FUNCTION_SELECTOR, transact_to=CONTRACT_ADDRESS\n    )\n\n    # 2. Create an EVM instance\n    evm = EVM(\n        cfg=cfg_env,\n        block=block_env,\n        tx=tx_env # Initial transaction environment\n    )\n\n    # 3. Insert initial state (e.g., contract code and account balances)\n    evm.insert_account_info(\n        CONTRACT_ADDRESS,\n        code=CONTRACT_CODE,\n        balance=0,\n        nonce=0\n    )\n    # Give caller some balance for transactions\n    evm.insert_account_info(\n        CALLER_ADDRESS,\n        balance=1_000_000_000_000_000_000, # 1 ETH\n        nonce=0\n    )\n\n    # 4. Perform a contract call\n    call_result = evm.call_raw() # Uses tx_env set during EVM init\n    \n    print(f\"--- Contract Call Simulation ---\")\n    print(f\"Status: {call_result.status}\")\n    print(f\"Gas Used: {call_result.gas_used}\")\n    print(f\"Exit Reason: {call_result.exit_reason}\")\n    print(f\"Output: {call_result.result.hex()}\")\n\n    # 5. Perform a simple value transfer transaction\n    recipient_address = bytes.fromhex(\"feeefeeefeeefeeefeeefeeefeeefeeefeeefeee\")\n    transfer_amount = 1000 # wei\n\n    # Update tx_env for the transaction\n    tx_env.data = b'' # No data for simple transfer\n    tx_env.transact_to = recipient_address\n    tx_env.value = transfer_amount\n\n    # Perform the transaction\n    transact_result = evm.transact_raw() # Uses updated tx_env\n    \n    print(f\"\\n--- Value Transfer Simulation ---\")\n    print(f\"Status: {transact_result.status}\")\n    print(f\"Gas Used: {transact_result.gas_used}\")\n    print(f\"Exit Reason: {transact_result.exit_reason}\")\n    print(f\"Output: {transact_result.result.hex()}\")\n\nif __name__ == \"__main__\":\n    run_evm_simulation()","lang":"python","description":"This quickstart demonstrates how to initialize an EVM instance, set up account states, and simulate both a contract call and a value transfer transaction using `pyrevm`. It requires `pyrevm` to be installed. Addresses and contract bytecode are provided as raw bytes for simplicity."},"warnings":[{"fix":"Ensure Rust and Cargo are installed (e.g., `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`). Prefer installing pre-built wheels when possible.","message":"pyrevm builds on a Rust core (revm). If pre-built wheels are not available for your specific Python version and operating system/architecture, you might need a Rust toolchain installed for `pip install` to compile from source. This is common on less mainstream platforms or with newer Python versions immediately after release.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Manage EVM instances carefully. For persistent state across multiple operations or snapshots, ensure you are either using the same `EVM` object or explicitly transferring/copying state as needed (e.g., via `evm.context.evm.clone()`).","message":"The EVM instance in `pyrevm` holds an in-memory state. Any changes (like balance transfers or contract state modifications) are local to that EVM instance. If you create a new `EVM` object, it starts with an empty state unless explicitly populated. State changes from one `EVM` object do not automatically persist to another.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always check the `pyrevm` and `revm` release notes when upgrading to a new major or minor version. Adapt your code to the updated API, paying close attention to `CfgEnv`, `BlockEnv`, `TxEnv`, and `EVM` constructor arguments and method calls.","message":"API changes in the underlying `revm` Rust library can lead to breaking changes in `pyrevm`'s Python API. While efforts are made to maintain compatibility, major version bumps of `revm` often cascade, affecting method signatures, class structures, or enum variants in `pyrevm`.","severity":"breaking","affected_versions":"Major version bumps (e.x., 0.x.y to 0.x+1.y)"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install pyrevm` in your terminal to install the library.","cause":"The pyrevm library is not installed or not available in the current Python environment.","error":"No module named 'pyrevm'"},{"fix":"Increase the `gas_limit` in your `TxEnv` and `BlockEnv` objects. For example, set `gas_limit=1_000_000_000` for a high limit during development, or analyze the required gas for your specific operation.","cause":"The transaction or call simulation exceeded the provided gas limit, or the block's gas limit.","error":"PyRevmError: EVM ran out of gas"},{"fix":"Verify that any target addresses or network configurations in your setup are correct and reachable. Ensure no firewalls are blocking connections if attempting to reach an external service. For local pyrevm, this error is generally not applicable unless misconfigured.","cause":"While less common for pyrevm (which is usually local), if you are attempting to integrate with a remote EVM or a service that pyrevm might internally try to connect to, this indicates a network connectivity issue or an invalid address/port.","error":"OSError: [Errno 99] Cannot assign requested address: Couldn't connect to remote EVM."},{"fix":"Double-check the source of your contract bytecode and ensure it is correctly compiled and passed as raw bytes. Verify that function selectors and arguments in `tx_env.data` are correctly formatted for the contract you are interacting with.","cause":"The bytecode provided to `insert_account_info` or the `data` field in `TxEnv` is malformed, not valid EVM bytecode, or does not match the expected function signature.","error":"PyRevmError: Invalid bytecode/contract code or input data"}]}