anvil - Create a local testnet node for deploying and testing smart contracts. It can also be used to fork other EVM compatible networks.
Create a local testnet node for deploying and testing smart contracts. It can also be used to fork other EVM compatible networks.
This section covers an extensive list of information about Mining Modes, Supported Transport Layers, Supported RPC Methods, Anvil flags and their usages. You can run multiple flags at the same time.
Mining modes refer to how frequent blocks are mined using Anvil. By default, it automatically generates a new block as soon as a transaction is submitted.
You can change this setting to interval mining if you will, which means that a new block will be generated in a given period of time selected by the user. If you want to go for this type of mining, you can do it by adding the
--block-time <block-time-in-seconds> flag, like in the following example.
# Produces a new block every 10 seconds anvil --block-time 10
There's also a third mining mode called never. In this case, it disables auto and interval mining, and mine on demand instead. You can do this by typing:
# Enables never mining mode anvil --no-mining
HTTP and Websocket connections are supported. The server listens on port 8545 by default, but it can be changed by running the following command:
anvil --port <PORT>
Anvil, when used without forking, includes the default CREATE2 deployer proxy at the address
This allows you to test CREATE2 deployments locally without forking.
The standard methods are based on this reference.
anvil --steps-tracingto get
debug_traceCallNote that non-standard traces are not yet support. This means you can't pass any arguments to the
anvil_* namespace is an alias for
hardhat. For more info, refer to the Hardhat documentation.
Send transactions impersonating an externally owned account or contract.
Stops impersonating an account or contract if previously set with
true to enable auto impersonation of accounts, and
false to disable it. When enabled, any transaction's sender will be automatically impersonated. Same as
Returns true if automatic mining is enabled, and false if it is not
Mines a series of blocks
Removes transactions from the pool
Reset the fork to a fresh forked state, and optionally update the fork config
Sets the backend RPC URL
Modifies the balance of an account
Sets the code of a contract
Sets the nonce of an address
Writes a single slot of the account's storage
Sets the coinbase address
Enable or disable logging
Set the minimum gas price for the node
Sets the base fee of the next block
Sets the chain ID of the current EVM instance
Returns a hex string representing the complete state of the chain. Can be re-imported into a fresh/restarted instance of Anvil to reattain the same state.
When given a hex string previously returned by
anvil_dumpState, merges the contents into the current chain state. Will overwrite any colliding accounts/storage slots.
Retrieves the configuration params for the currently running Anvil node.
The special methods come from Ganache. You can take a look at the documentation here.
Enables or disables, based on the single boolean argument, the automatic mining of new blocks with each new transaction submitted to the network
Sets the mining behavior to interval with the given interval (seconds)
Snapshot the state of the blockchain at the current block
Revert the state of the blockchain to a previous snapshot. Takes a single parameter, which is the snapshot id to revert to
Jump forward in time by the given amount of time, in seconds
evm_increaseTime but takes the exact timestamp that you want in the next block
evm_increaseTime but sets a block timestamp
interval. The timestamp of the next block will be computed as
lastBlock_timestamp + interval
Sets the block gas limit for the following blocks
anvil_setBlockTimestampInterval if it exists
Mine a single block
Turn on call traces for transactions that are returned to the user when they execute a transaction (instead of just txhash/receipt)
Execute a transaction regardless of signature status
For the next three methods, make sure to read Geth's documentation.
Returns the number of transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only
Returns a summary of all the transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only
Returns the details of all transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only
ots_* namespace implements the Otterscan specification
Used by Otterscan to check if it's connecting to a compatible node and display a friendly message if it is not.
Returns the internal ETH transfers inside a transaction.
Check if a certain address contains a deployed code.
Extract the transaction raw error output.
Extract all variations of calls, contract creation and self-destructs and returns a call tree.
Tailor-made and expanded version of eth_getBlock* for block details page in Otterscan.
Get paginated transactions for a certain block, And removes some verbose fields such logs.
Gets paginated inbound/outbound transaction calls for a certain address, and before a given target block
Gets paginated inbound/outbound transaction calls for a certain address, and after a given target block
Gets the transaction hash for a certain sender address, given its nonce.
Gets the transaction hash and the address which created a contract.
-a, --accounts <ACCOUNTS>
Set the number of accounts [default: 10]
Enable autoImpersonate on startup
-b, --block-time <block-time>
Block time in seconds for interval mining
Set the balance of the accounts [default: 10000]
Set the derivation path of the child key to be derived [default: m/44'/60'/0'/0/]
Print help information
Choose the EVM hardfork to use
Choose the hardfork by name, e.g.
Initialize the genesis block with the given
-m, --mnemonic <MNEMONIC>
BIP39 mnemonic phrase used for generating accounts
Disable auto and interval mining, and mine on demand instead
How transactions are sorted in the mempool [default: fees]
-p, --port <PORT>
Port number to listen on [default: 8545]
Enable steps tracing used for debug calls returning geth-style traces [aliases: tracing]
Starts an IPC endpoint at the given
PATH argument or the default path: unix:
Don't print anything on startup
Set the timestamp of the genesis block
Print version information
Disables deploying the default CREATE2 factory when running Anvil without forking
-f, --fork-url <URL>
Fetch state over a remote endpoint instead of starting from an empty state
Fetch state from a specific block number over a remote endpoint (Must pass --fork-url in the same command-line)
Initial retry backoff on encountering errors.
Number of retry requests for spurious networks (timed out requests). [default value= 5]
Timeout in ms for requests sent to remote JSON-RPC server in forking mode. [default value= 45000]
Sets the number of assumed available compute units per second for this provider [default value=330]
See also, Alchemy Ratelimits
Disables rate limiting for this node's provider. Will always override
--compute-units-per-second if present. [default value= false]
See also, Alchemy Ratelimits
Explicitly disables the use of RPC caching. All storage slots are read entirely from the endpoint. This flag overrides the project's configuration file (Must pass --fork-url in the same command-line)
The base fee in a block
The chain ID [default: 31337]
EIP-170: Contract code size limit in bytes. Useful to increase this because of tests.
By default, it is 0x6000 (~25kb)
The block gas limit
The gas price
Set the CORS allow_origin [default: *]
The IP address the server will listen on
Writes output of
anvil as json to user-specified file
Don't keep full chain history
- Set the number of accounts to 15 and their balance to 300 ETH
anvil --accounts 15 --balance 300
- Choose the address which will execute the tests
anvil --sender 0xC8479C45EE87E0B437c09d3b8FE8ED14ccDa825E
- Change how transactions are sorted in the mempool to FIFO
anvil --order fifo
anvil completions shell
Generates a shell completions script for the given shell.
Supported shells are:
- Generate shell completions script for zsh:
anvil completions zsh > $HOME/.oh-my-zsh/completions/_anvil
In order to run anvil as a service in Github Actions with the Docker container, where passing arguments to the entrypoint command is not possible, use the
ANVIL_IP_ADDR environment variable to set the host's IP.
ANVIL_IP_ADDR=0.0.0.0 is equivalent to providing the
--host <ip> option.