eth_networks
Ethereum Network Configuration Module
Provides built-in configurations for popular EVM-compatible networks with default public RPC endpoints. Supports custom network configuration.
- class eth_networks.NetworkConfig(name, chain_id, rpc_url, native_symbol, native_decimals=18, explorer_url=None, is_testnet=False)[source]
Bases:
objectImmutable description of a single EVM-compatible chain.
Bundles the connection and display metadata the wallet tooling needs to talk to one network: its human name, numeric
chain_id, JSON-RPC endpoint, native-currency symbol/decimals, block-explorer URL, and a testnet flag. Every entry in the module-levelNETWORKSregistry is one of these, and custom user-supplied chains are built into the same shape bycreate_custom_network().Instances are consumed by
tools/eth_wallet_tools.py(viaget_network()/create_custom_network()) to resolve which RPC URL and chain id to sign and broadcast transactions against; the dataclass is plain data and performs no I/O itself.- Parameters:
- is_testnet: bool = False
True for test networks, used to filter them out of
list_networks()results.
- to_dict()[source]
Flatten this config into a plain JSON-serializable dictionary.
Produces a one-to-one mapping of every field so the network can be embedded in tool responses or API payloads without exposing the dataclass type. Pure data transformation with no side effects; the keys mirror the attribute names exactly.
No callers were found in the repository (grep for
.to_dict(on a network config returns only the definitions), so this is a convenience serializer available to tool handlers rather than something currently wired into a hot path.
- eth_networks.get_network(network_name_or_id)[source]
Resolve a network by its name/alias or numeric chain id.
The primary lookup the wallet tooling uses to turn a user-supplied identifier into a concrete RPC target. It first tries a case-insensitive, whitespace-trimmed match against the
NETWORKSregistry keys (which include short aliases likeethorop); failing that, it treats the argument as a decimal chain id and scansNETWORKSfor the first config with a matchingchain_id. The registry is in-memory, so no network I/O happens here.Called by
tools/eth_wallet_tools.py(_resolve_networkand related handlers) to pick the chain a transaction or balance query runs against; when it returnsNonethe tool layer falls back tocreate_custom_network()or reports an unknown-network error.- Parameters:
network_name_or_id (
str) – A registry key/alias (ethereum,base) or a decimal chain id rendered as a string ("1","8453").- Returns:
The matching network config, or
Noneif no name alias or chain id matches.- Return type:
- eth_networks.get_network_by_chain_id(chain_id)[source]
Look up a network config by its exact numeric chain id.
A narrower, integer-typed sibling of
get_network()that skips the name-alias path and linearly scans theNETWORKSregistry for the first config whosechain_idequals the argument. Because several aliases share a chain id, the first registry entry encountered wins. In-memory only, no I/O.No callers were found in the repository outside this module’s own definition, so it is currently an unused public helper kept for symmetry with
get_network()and for external/tool callers.- Parameters:
chain_id (
int) – The EIP-155 chain id to match.- Returns:
The matching config, or
Noneif no registered network uses that chain id.- Return type:
- eth_networks.create_custom_network(name, chain_id, rpc_url, native_symbol='ETH', native_decimals=18, explorer_url=None, is_testnet=False)[source]
Build an ad-hoc
NetworkConfigfrom caller-supplied parameters.Lets the wallet tooling target chains that are not in the built-in
NETWORKSregistry: the caller passes an explicit RPC URL and chain id and gets back a config of the same shape as the built-ins, so the rest of the signing/broadcast path is identical. This is a thin constructor wrapper that just forwards its arguments toNetworkConfig; it does not register the result, validate the RPC, or perform any I/O.Called by
tools/eth_wallet_tools.py(_resolve_network) whenget_network()returnsNonefor a chain id but the caller provided a custom RPC endpoint to use.- Parameters:
name (
str) – Human-readable network name.chain_id (
int) – EIP-155 chain id for transaction signing.rpc_url (
str) – JSON-RPC endpoint to connect to.native_symbol (
str) – Native-token ticker; defaults toETH.native_decimals (
int) – Native-token decimal places; defaults to 18.explorer_url (
Optional[str]) – Block-explorer base URL, if known.is_testnet (
bool) – Whether this should be treated as a test network.
- Returns:
A freshly constructed config wrapping the given values.
- Return type:
- eth_networks.list_networks(include_testnets=True)[source]
Summarize the registered networks, one entry per unique chain.
Produces a de-duplicated, display-oriented listing of
NETWORKS: it walks the registry, keeps only the first config seen for eachchain_id(so the many name aliases collapse to a single row), optionally drops testnets, and returns lightweight summary dicts sorted with mainnets first and then alphabetically by name. Read-only over the in-memory registry.Called by
tools/eth_wallet_tools.py(thelist_eth_networkstool handler at line 749) to present the available chains to the model/user.