crates/evm/networks/README.md
The evm-networks crate defines custom network features that are shared across Foundry's tooling (anvil, forge and
cast). Currently, it supports custom precompiles, with planned support for custom transaction types.
To add configuration support for a custom network (e.g. my_network), add a new field to the NetworkConfigs struct:
/// Enable my custom network features.
#[arg(help_heading = "Networks", long)]
#[serde(default)]
pub my_network: bool,
This automatically enables:
my_network = true in foundry.toml--my-network anvil CLI flagNetworks:
--my-network
Enable my custom network features
If you'd like network features to be enabled automatically based on the chain ID, update NetworkConfigs::with_chain_id:
impl NetworkConfigs {
pub fn with_chain_id(chain_id: u64) -> Self {
// Enable custom network features here
}
}
my_network/transfer.PrecompileInput containing execution context and hooks for
interacting with EVM state, and returns a PrecompileResult:pub fn custom_precompile(
input: alloy_evm::precompiles::PrecompileInput<'_>
) -> revm::precompile::PrecompileResult {
// Your logic here
}
NetworkConfigs implementation by conditionally applying it to an address:if self.my_network {
precompiles.apply_precompile(&MY_NETWORK_TRANSFER_ADDRESS, move |_| {
Some(my_network::transfer::custom_precompile())
});
}