Anchor.toml file is the configuration file for Anchor workspaces. It defines workspace settings, program deployments, testing configuration, and build options.
File Structure
A completeAnchor.toml with all sections:
Required Sections
[provider]
Specifies the default cluster and wallet for all Anchor commands.localnet- Local test validator (default: http://127.0.0.1:8899)devnet- Solana devnetmainnet- Solana mainnet-beta- Custom URL:
"https://api.devnet.solana.com" - Custom with WebSocket:
[scripts]
Defines executable scripts for your workspace. Thetest script is required for anchor test.
Optional Sections
[toolchain]
Override toolchain versions and settings for the workspace.npm- Node Package Manageryarn- Yarn (default)pnpm- PNPMbun- Bun runtime
The
anchor_version field requires AVM (Anchor Version Manager) to be installed.[features]
Configure Anchor framework features.// UNSAFE, // TODO) in generated code.
[registry]
Configure the Anchor Package Registry (APR) URL.programs.cluster configuration
Map program library names to their on-chain addresses for each cluster.Program IDs must match the
declare_id!() in your program code. Use anchor keys sync to update program IDs.[workspace]
Configure workspace member programs and TypeScript type generation.programs/* if not specified.
types: When set, anchor build copies generated <program>.ts IDL files to this directory.
[hooks]
Run commands at specific stages of the build/test/deploy pipeline.pre-build/post-build- Run before/afteranchor buildpre-test/post-test- Run before/afteranchor testpre-deploy/post-deploy- Run before/afteranchor deploy
- Single command:
hook = "command" - Multiple commands:
hook = ["cmd1", "cmd2"](run in series) - Non-zero exit code aborts the operation
- Supports both kebab-case (
pre-build) and snake_case (pre_build)
[test]
Configure test validator behavior.true, deploys with --upgradeable flag. Initial upgrade authority is set to provider.wallet.
[[test.genesis]]
Load programs at genesis when starting the test validator.[[test.genesis]] for multiple entries.
[test.validator]
Configure the Solana test validator options.[[test.validator.clone]]
Clone accounts from the configured cluster.For upgradeable programs, Anchor automatically clones the program data account.
[[test.validator.account]]
Load account data from JSON files.Command Line Overrides
OverrideAnchor.toml settings via command line:
Environment Variables
Set provider options via environment variables:Example Configurations
Minimal Configuration
Anchor.toml
Production Configuration
Anchor.toml
Testing with Mainnet Forks
Anchor.toml
Best Practices
Pin Versions in Production
Pin Versions in Production
Always specify exact versions:
Use Different Program IDs per Cluster
Use Different Program IDs per Cluster
Maintain separate program IDs for testing and production:
Commit Anchor.toml
Commit Anchor.toml
Always version control your
Anchor.toml:Use Hooks for Build Verification
Use Hooks for Build Verification
Automate verification in your deployment workflow: