A fast local Ethereum development node
Examples:
- anvil (start a local node on 127.0.0.1:8545)
- anvil --fork-url $RPC_URL (fork the latest state of a live network)
- anvil --block-time 12 (mine a new block every 12 seconds)
- anvil --state state.json (load state if it exists and dump it on exit)
Usage: anvil [OPTIONS] [COMMAND]
Commands:
completions Generate shell completions script [alias: com]
help Print this message or the help of the given subcommand(s)
Options:
-a, --accounts <NUM>
Number of dev accounts to generate and configure
[default: 10]
-b, --block-time <SECONDS>
Block time in seconds for interval mining
[alias: --blockTime]
--balance <NUM>
The balance of every dev account in Ether
[default: 10000]
--config-out <FILE>
Writes output of `anvil` as json to user-specified file
--derivation-path <DERIVATION_PATH>
Sets the derivation path of the child key to be derived.
[default: m/44'/60'/0'/0/]
--dump-state <PATH>
Dump the state and block environment of chain on exit to the given file.
If the value is a directory, the state will be written to `<VALUE>/state.json`.
--fund-accounts <ADDRESS:AMOUNT>...
Fund specific accounts with custom balances on startup.
Accepts multiple address:balance pairs where balance is in ETH. Example: --fund-accounts
0x1234...5678:1000 0xabcd...ef01:5000
-h, --help
Print help (see a summary with '-h')
--hardfork <HARDFORK>
The EVM hardfork to use.
Choose the hardfork by name, e.g. `prague`, `cancun`, `shanghai`, `paris`, `london`,
etc... [default: latest]
--init <PATH>
Initialize the genesis block with the given `genesis.json` file
--ipc [<PATH>]
Launch an ipc server at the given path or default path = `/tmp/anvil.ipc`
[alias: --ipcpath]
-j, --threads <THREADS>
Number of threads to use. Specifying 0 defaults to the number of logical cores
[alias: --jobs]
--load-state <PATH>
Initialize the chain from a previously saved state snapshot
-m, --mnemonic <MNEMONIC>
BIP39 mnemonic phrase used for generating accounts. Cannot be used if `mnemonic_random` or
`mnemonic_seed` are used
--max-persisted-states <MAX_PERSISTED_STATES>
Max number of states to persist on disk.
Note that `prune_history` will overwrite `max_persisted_states` to 0.
--max-transactions <MAX_TRANSACTIONS>
Maximum number of transactions in a block
--mixed-mining
Enable mixed mining mode. Blocks are mined on a timer (set by `--block-time`), but also
whenever a transaction is submitted. Requires `--block-time` to be set
--mnemonic-random [<MNEMONIC_RANDOM>]
Automatically generates a BIP39 mnemonic phrase, and derives accounts from it. Cannot be
used with other `mnemonic` options. You can specify the number of words you want in the
mnemonic. [default: 12]
--mnemonic-seed-unsafe <MNEMONIC_SEED>
Generates a BIP39 mnemonic phrase from a given seed Cannot be used with other `mnemonic`
options.
CAREFUL: This is NOT SAFE and should only be used for testing. Never use the private keys
generated in production.
--no-mining
Disable auto and interval mining, and mine on demand instead
[alias: --no-mine]
--number <NUM>
The number of the genesis block
--order <ORDER>
How transactions are sorted in the mempool
[default: fees]
-p, --port <NUM>
Port number to listen on
[default: 8545]
--preserve-historical-states
Preserve historical state snapshots when dumping the state.
This will save the in-memory states of the chain at particular block hashes.
These historical states will be loaded into the memory when `--load-state` / `--state`,
and aids in RPC calls beyond the block at which state was dumped.
--profile <PROFILE>
The configuration profile to use
--prune-history [<PRUNE_HISTORY>]
Don't keep full chain history. If a number argument is specified, at most this number of
states is kept in memory.
If enabled, no state will be persisted on disk, so `max_persisted_states` will be 0.
-s, --state-interval <SECONDS>
Interval in seconds at which the state and block environment is to be dumped to disk.
See --state and --dump-state
--slots-in-an-epoch <SLOTS_IN_AN_EPOCH>
Slots in an epoch
[default: 32]
--state <PATH>
This is an alias for both --load-state and --dump-state.
It initializes the chain with the state and block environment stored at the file, if it
exists, and dumps the chain's state on exit.
--tempo.consensus-seed <SEED>
Development consensus seed for Tempo, as 32 bytes of hex.
Defaults to a domain-separated hash of the dev-account mnemonic. Only used on Tempo
networks.
--tempo.epoch-length <BLOCKS>
Number of block heights in a Tempo consensus epoch. Only used on Tempo networks
[default: 21600]
--tempo.fee-payer <ADDRESS>
The account used to sponsor Tempo fee-payer requests (`eth_signRawTransaction` and raw
transactions carrying the sponsorship placeholder).
Must be an unlocked account. Only used on Tempo networks; defaults to the last dev
account.
--timestamp <NUM>
The timestamp of the genesis block
--transaction-block-keeper <TRANSACTION_BLOCK_KEEPER>
Number of blocks with transactions to keep in memory
--transaction-coalescing-window <MILLISECONDS>
Time in milliseconds to group ready transactions into one auto-mined block. Defaults to 0
(no delay). Set a positive value to enable transaction coalescing
[default: 0]
-V, --version
Print version
Display options:
--color <COLOR>
The color of the log messages
Possible values:
- auto: Intelligently guess whether to use color output (default)
- always: Force color output
- never: Force disable color output
--json
Format log messages as JSON
--md
Format log messages as Markdown
-q, --quiet
Do not print log messages
-v, --verbosity...
Verbosity level of the log messages.
Pass multiple times to increase the verbosity (e.g. -v, -vv, -vvv).
Depending on the context the verbosity levels have different meanings.
For example, the verbosity levels of the EVM are:
- 2 (-vv): Print logs for all tests.
- 3 (-vvv): Print execution traces for failing tests.
- 4 (-vvvv): Print execution traces for all tests, and setup traces for failing tests.
- 5 (-vvvvv): Print execution and setup traces for all tests, including storage changes
and
backtraces with line numbers.
Server options:
--allow-origin <ALLOW_ORIGIN>
The cors `allow_origin` header
[default: *]
--cache-path <PATH>
Path to the cache directory where persisted states are stored (see
`--max-persisted-states`).
Note: This does not affect the fork RPC cache location, which uses endpoint-specific files
under `~/.foundry/cache/rpc/<chain>/<block>/`.
--host <IP_ADDR>
The hosts the server will listen on
[env: ANVIL_IP_ADDR=]
[default: 127.0.0.1]
--no-cors
Disable CORS
--no-request-size-limit
Disable the default request body size limit. At time of writing the default limit is 2MB
Fork config:
--compute-units-per-second <CUPS>
Sets the number of assumed available compute units per second for this provider
default value: 330
See also --fork-url and
<https://docs.alchemy.com/reference/compute-units#what-are-cups-compute-units-per-second>
-f, --fork-url <URL>
Fetch state over a remote endpoint instead of starting from an empty state.
If you want to fetch state from a specific block number, add a block number like
`http://localhost:8545@1400000` or use the `--fork-block-number` argument.
Multiple `--fork-url` flags can be provided to distribute requests across endpoints using
round-robin load balancing. On failure, the retry layer rotates to the next endpoint.
[alias: --rpc-url]
--fork-block-number <BLOCK>
Fetch state from a specific block number over a remote endpoint.
If negative, the given value is subtracted from the `latest` block number.
See --fork-url.
--fork-chain-id <CHAIN>
Specify chain id to skip fetching it from remote endpoint. This enables offline-start
mode.
You still must pass both `--fork-url` and `--fork-block-number`, and already have your
required state cached on disk, anything missing locally would be fetched from the remote.
--fork-header <HEADERS>
Headers to use for the rpc client, e.g. "User-Agent: test-agent"
See --fork-url.
--fork-retry-backoff <BACKOFF>
Initial retry backoff on encountering errors.
See --fork-url.
--fork-state-by-number
Read fork state by block number instead of by block hash.
Use this for RPCs that cannot serve `eth_getBalance`, `eth_getCode`, `eth_getStorageAt` or
`eth_getTransactionCount` for a block hash. Block hash ancestry is still validated against
the fork block.
See --fork-url.
--fork-transaction-hash <TRANSACTION>
Fetch state from after a specific transaction hash has been applied over a remote
endpoint.
See --fork-url.
--no-bal
Disable pre-filling the fork cache with block access list (BAL) post-state.
By default, eligible Ethereum forks briefly try fetching a BAL at the fork block. Missing
or invalid BALs fall back to ordinary state reads. This setting also applies to subsequent
resets and does not disable serving BAL RPC methods.
--no-fork-node-info
Do not probe the fork endpoint with `anvil_nodeInfo` / `anvil_metadata`.
Those calls detect a nested Anvil. Some public RPCs retry unknown methods for tens of
seconds instead of returning method-not-found, which delays listen until the probe
finishes.
--no-rate-limit
Disables rate limiting for this node's provider.
default value: false
See also --fork-url and
<https://docs.alchemy.com/reference/compute-units#what-are-cups-compute-units-per-second>
[alias: --no-rpc-rate-limit]
--no-storage-caching
Explicitly disables the use of RPC caching.
All storage slots are read entirely from the endpoint.
This flag overrides the project's configuration file.
See --fork-url.
--retries <retries>
Number of retry requests for spurious networks (timed out requests)
Default value 5
--timeout <timeout>
Timeout in ms for requests sent to remote JSON-RPC server in forking mode.
Default value 45000
Environment config:
--block-base-fee-per-gas <FEE>
The base fee in a block
[alias: --base-fee]
--chain-id <CHAIN_ID>
The chain ID
--code-size-limit <CODE_SIZE>
EIP-170: Contract code size limit in bytes. Useful to increase this because of tests. To
disable entirely, use `--disable-code-size-limit`. By default, it is 0x6000 (~25kb)
--disable-block-gas-limit
Disable the `call.gas_limit <= block.gas_limit` constraint
--disable-code-size-limit
Disable EIP-170: Contract code size limit
--disable-min-priority-fee
Disable the enforcement of a minimum suggested priority fee
[alias: --no-priority-fee]
--enable-tx-gas-limit
Enable the transaction gas limit check as imposed by EIP-7825 (Osaka hardfork).
From Amsterdam, the cap always applies to regular gas only, and gas above it becomes the
EIP-8037 state gas reservoir.
[alias: --tx-gas-limit]
--gas-limit <GAS_LIMIT>
The block gas limit
--gas-price <GAS_PRICE>
The gas price
EVM options:
--auto-impersonate
Enables automatic impersonation on startup. This allows any transaction sender to be
simulated as different accounts, which is useful for testing contract behavior
[alias: --auto-unlock]
--disable-console-log
Disable printing of `console.log` invocations to stdout
[alias: --no-console-log]
--disable-default-create2-deployer
Disable the default create2 deployer
[alias: --no-create2]
--disable-pool-balance-checks
Disable pool balance checks
--memory-limit <MEMORY_LIMIT>
The memory limit per EVM execution in bytes
--print-traces
Enable printing of traces for executed transactions and `eth_call` to stdout
[alias: --enable-trace-printing]
--steps-tracing
Enable steps tracing used for debug calls returning geth-style traces
Steps are recorded by replaying the transaction from its parent block's state, so they are
unavailable once that state is pruned or when loading a state dump created without
`--preserve-historical-states`.
[alias: --tracing]
Networks:
--celo
Enable Celo network features
-n, --network <NETWORK>
Enable a specific network family
[possible values: ethereum, optimism, tempo, monad]
Options (78)
| Option | Description | Source |
|---|---|---|
-a, --accounts NUM | Number of dev accounts to generate and configure | help |
-b, --block-time SECONDS | Block time in seconds for interval mining | help |
--balance NUM | The balance of every dev account in Ether | help |
--config-out FILE | Writes output of `anvil` as json to user-specified file | help |
--derivation-path DERIVATION_PATH | Sets the derivation path of the child key to be derived. | help |
--dump-state PATH | Dump the state and block environment of chain on exit to the given file. | help |
--fund-accounts ADDRESS:AMOUNT>... | Fund specific accounts with custom balances on startup. | help |
-h, --help | Print help (see a summary with '-h') | help |
--hardfork HARDFORK | The EVM hardfork to use. | help |
--init PATH | Initialize the genesis block with the given `genesis.json` file | help |
--ipc PATH | Launch an ipc server at the given path or default path = `/tmp/anvil.ipc` | help |
-j, --threads THREADS | Number of threads to use. | help |
--load-state PATH | Initialize the chain from a previously saved state snapshot | help |
-m, --mnemonic MNEMONIC | BIP39 mnemonic phrase used for generating accounts. | help |
--max-persisted-states MAX_PERSISTED_STATES | Max number of states to persist on disk. | help |
--max-transactions MAX_TRANSACTIONS | Maximum number of transactions in a block | help |
--mixed-mining | Enable mixed mining mode. | help |
--mnemonic-random MNEMONIC_RANDOM | Automatically generates a BIP39 mnemonic phrase, and derives accounts from it. | help |
--mnemonic-seed-unsafe MNEMONIC_SEED | Generates a BIP39 mnemonic phrase from a given seed Cannot be used with other `mnemonic` options. | help |
--no-mining | Disable auto and interval mining, and mine on demand instead | help |
--number NUM | The number of the genesis block | help |
--order ORDER | How transactions are sorted in the mempool | help |
-p, --port NUM | Port number to listen on | help |
--preserve-historical-states | Preserve historical state snapshots when dumping the state. | help |
--profile PROFILE | The configuration profile to use | help |
--prune-history PRUNE_HISTORY | Don't keep full chain history. | help |
-s, --state-interval SECONDS | Interval in seconds at which the state and block environment is to be dumped to disk. | help |
--slots-in-an-epoch SLOTS_IN_AN_EPOCH | Slots in an epoch | help |
--state PATH | This is an alias for both --load-state and --dump-state. | help |
--tempo.consensus-seed SEED | Development consensus seed for Tempo, as 32 bytes of hex. | help |
--tempo.epoch-length BLOCKS | Number of block heights in a Tempo consensus epoch. | help |
--tempo.fee-payer ADDRESS | The account used to sponsor Tempo fee-payer requests (`eth_signRawTransaction` and raw transactions carrying the sponsorship placeholder). | help |
--timestamp NUM | The timestamp of the genesis block | help |
--transaction-block-keeper TRANSACTION_BLOCK_KEEPER | Number of blocks with transactions to keep in memory | help |
--transaction-coalescing-window MILLISECONDS | Time in milliseconds to group ready transactions into one auto-mined block. | help |
-V, --version | Print version | help |
--color COLOR | The color of the log messages | help |
--json | Format log messages as JSON | help |
--md | Format log messages as Markdown | help |
-q, --quiet | Do not print log messages | help |
-v, --verbosity | Verbosity level of the log messages. | help |
--allow-origin ALLOW_ORIGIN | The cors `allow_origin` header | help |
--cache-path PATH | Path to the cache directory where persisted states are stored (see `--max-persisted-states`). | help |
--host IP_ADDR | The hosts the server will listen on | help |
--no-cors | Disable CORS | help |
--no-request-size-limit | Disable the default request body size limit. | help |
--compute-units-per-second CUPS | Sets the number of assumed available compute units per second for this provider | help |
-f, --fork-url URL | Fetch state over a remote endpoint instead of starting from an empty state. | help |
--fork-block-number BLOCK | Fetch state from a specific block number over a remote endpoint. | help |
--fork-chain-id CHAIN | Specify chain id to skip fetching it from remote endpoint. | help |
--fork-header HEADERS | Headers to use for the rpc client, e.g. "User-Agent: test-agent" | help |
--fork-retry-backoff BACKOFF | Initial retry backoff on encountering errors. | help |
--fork-state-by-number | Read fork state by block number instead of by block hash. | help |
--fork-transaction-hash TRANSACTION | Fetch state from after a specific transaction hash has been applied over a remote endpoint. | help |
--no-bal | Disable pre-filling the fork cache with block access list (BAL) post-state. | help |
--no-fork-node-info | Do not probe the fork endpoint with `anvil_nodeInfo` / `anvil_metadata`. | help |
--no-rate-limit | Disables rate limiting for this node's provider. | help |
--no-storage-caching | Explicitly disables the use of RPC caching. | help |
--retries retries | Number of retry requests for spurious networks (timed out requests) | help |
--timeout timeout | Timeout in ms for requests sent to remote JSON-RPC server in forking mode. | help |
--block-base-fee-per-gas FEE | The base fee in a block | help |
--chain-id CHAIN_ID | The chain ID | help |
--code-size-limit CODE_SIZE | EIP-170: Contract code size limit in bytes. | help |
--disable-block-gas-limit | Disable the `call.gas_limit <= block.gas_limit` constraint | help |
--disable-code-size-limit | Disable EIP-170: Contract code size limit | help |
--disable-min-priority-fee | Disable the enforcement of a minimum suggested priority fee | help |
--enable-tx-gas-limit | Enable the transaction gas limit check as imposed by EIP-7825 (Osaka hardfork). | help |
--gas-limit GAS_LIMIT | The block gas limit | help |
--gas-price GAS_PRICE | The gas price | help |
--auto-impersonate | Enables automatic impersonation on startup. | help |
--disable-console-log | Disable printing of `console.log` invocations to stdout | help |
--disable-default-create2-deployer | Disable the default create2 deployer | help |
--disable-pool-balance-checks | Disable pool balance checks | help |
--memory-limit MEMORY_LIMIT | The memory limit per EVM execution in bytes | help |
--print-traces | Enable printing of traces for executed transactions and `eth_call` to stdout | help |
--steps-tracing | Enable steps tracing used for debug calls returning geth-style traces | help |
--celo | Enable Celo network features | help |
-n, --network NETWORK | Enable a specific network family | help |