AnvilLaunch

Documentation for eth_defi.provider.anvil.AnvilLaunch Python class.

class AnvilLaunch

Bases: object

Control Anvil processes launched on background.

Comes with a helpful close() method when it is time to put Anvil rest.

The chain_id, upstream_rpc_urls, fork_block_number and effective_fork_url fields are the canonical launch metadata exposed to callers. The module-level metadata registry mirrors these values only so that later create_multi_provider_web3(launch.json_rpc_url) calls can attach the same context to retry diagnostics.

Attributes summary

chain_id

Chain id reported by the local Anvil instance after startup.

effective_fork_url

URL passed to Anvil as --fork-url.

fork_block_number

Explicit fork block used for Anvil, if any.

proxy

Optional JSON-RPC failover proxy sitting between Anvil and upstream RPCs.

upstream_rpc_urls

Original upstream RPC URLs passed to Anvil fork mode.

port

Which port was bound by the Anvil

cmd

Used command-line to spin up anvil

json_rpc_url

Where does Anvil listen to JSON-RPC

process

UNIX process that we opened

Methods summary

__init__(port, cmd, json_rpc_url, process[, ...])

close([log_level, block, block_timeout])

Close the background Anvil process.

port: int

Which port was bound by the Anvil

cmd: list[str]

Used command-line to spin up anvil

json_rpc_url: str

Where does Anvil listen to JSON-RPC

process: psutil.Popen

UNIX process that we opened

chain_id: Optional[int] = None

Chain id reported by the local Anvil instance after startup.

upstream_rpc_urls: tuple[str, ...] = ()

Original upstream RPC URLs passed to Anvil fork mode.

fork_block_number: Optional[int] = None

Explicit fork block used for Anvil, if any.

effective_fork_url: Optional[str] = None

URL passed to Anvil as --fork-url.

proxy: RPCProxy | None = None

Optional JSON-RPC failover proxy sitting between Anvil and upstream RPCs. Automatically started by launch_anvil() when multiple RPCs are configured in space-separated fork_url and proxy_multiple_upstream is not False. See eth_defi.provider.rpc_proxy.

close(log_level=None, block=True, block_timeout=30)

Close the background Anvil process.

If this instance owns the RPCProxy (i.e. it was auto-created, not passed in by the caller), the proxy is shut down after Anvil exits and its per-provider statistics are logged. Port-lease release runs from nested finally blocks, so a shutdown or managed-proxy cleanup error cannot strand the lease until the Python worker exits.

Parameters
  • log_level (Optional[int]) – Dump Anvil messages to logging

  • block – Block the execution until anvil is gone

  • block_timeout – How long time we try to kill Anvil until giving up.

Returns

Anvil stdout, stderr as string

Return type

tuple[bytes, bytes]

__init__(port, cmd, json_rpc_url, process, chain_id=None, upstream_rpc_urls=(), fork_block_number=None, effective_fork_url=None, proxy=None, _proxy_managed=True, _port_lease=None)
Parameters
Return type

None