Hardhat allows users to configure a custom network in the networks configuration object. This allows developers to run their JS/TS test suites against another local node such as Ganache or even a live network such as an Ethereum testnet.
Can this be done in Foundry as well? For example, instead of using Foundry's default node Anvil users can specify a locally running node such as a hardhat or ganache local node that they want to run their Foundry project's test suites(written in solidity) on.
Best Answer
Yes, Foundry allows users to configure custom Ethereum nodes.
RPC-Endpoints settings
Custom RPC endpoints can be defined in the
foundry.toml
under[rpc_endpoints]
as follows:Forge Commands
forge commands typically have a flag that allows you to run various commands with specified network configurations using either an explicit RPC URL or a network alias defined in the
foundry.toml
Testing with a Forked Environment:
--rpc-url
,--fork-url
and-f
are valid options for forge testDeploying contracts to a network
--rpc-url
is a valid option for forge createRunning solidity scripts against a network
--rpc-url
,--fork-url
and-f
are valid options for forge script