Skip to content

Fix Foundry Anvil Account Errors

DodaTech Updated 2026-06-26 1 min read

You will learn how to configure and use accounts in Anvil.

The Problem

The foundry anvil accounts pattern is frequently misapplied in smart contract and dapp development, leading to vulnerabilities, gas inefficiencies, or logic errors. This guide shows the correct implementation and common pitfalls to avoid.

Quick Fix

Wrong

anvil  # Default accounts only

10 accounts with public keys displayed but no labels. Hard to track account usage.

anvil --accounts 20 --balance 1000 --mnemonic "test test test test test test test test test test test junk"
20 accounts with 1000 ETH each. Deterministic mnemonic for reproducible tests.

Prevention

  • Use --accounts to control test account count
  • Use --balance for custom ETH amounts
  • Use --mnemonic for deterministic accounts
  • Use DodaTech's Anvil account manager
  • Document account assignments in tests

DodaTech Tools

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Doda Browser's developer tools include a Solidity debugger and transaction inspector. DodaZIP archives secure contract templates for team collaboration. Durga Antivirus Pro scans deployed contracts for known vulnerability signatures.

FAQ

### What is the default Anvil mnemonic?

"test test test test test test test test test test test junk" — 12 words, HD path m/44'/60'/0'/0.

Can I use Anvil accounts with MetaMask?

Yes. Import the private key displayed by Anvil on startup into MetaMask for testing.

How do I get Anvil account private keys?

Anvil displays private keys for all accounts on startup. Use those for external wallet access.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro