Impersonator

The Impersonator wallet allows you to impersonate any account on the chain, by using the anvil_impersonateAccount RPC endpoint.

This is useful for testing, as it allows you to submit transactions without having to unlock your wallet, and enables fast mode to work on secure wallets as well.

Why?

This is actually a security feature that happens to be very convenient for development.

Let's say you're spawning the following anvil node:

anvil --chain-id 1

This could open you up for replay attacks, where you end up signing a payload that can actually end up being used on the real mainnet chain to execute a real transaction, either maliciously or by mistake.

By auto-impersonating accounts, you now skip the signing step, but are still able to include transactions on the test chain. In the end:

  • you never have to actually unlock your wallet
  • no signature is ever produced from your private key
  • fast mode can be used