🔥Forge

Inspect

List out all the methods and function selectors in a contract
forge inspect <CONTRACT_NAME> methods
Inspect contract and view storage layout
forge inspect <CONTRACT_NAME> storageLayout
Create .gas-snapshot for all tests
forge snapshot

If you see the error EvmError: NotActivated when trying to deploy contracts using forge it may be that you need to explicitly set the --evm-version when running the forge command.

The evm version can also be set in the foundry.toml file:

[profile.default]
evm_version = "cancun"

Contract Verification

If automatic contract verification fails during deployment it can be performed manually using forge.

forge verify-contract <CONTRACT_ADDRESS> ./src/<CONTRACT>.sol:<CONTRACT_NAME> --chain-id <CHAIN_ID> --watch --etherscan-api-key <ETHERSCAN_API_KEY>
  • --watch leaves the terminal waiting for a status confirmation reply.

  • If constructor arguments are required they can be encoded using cast e.g for a constructor requiring a single address:

cast abi-encode "constructor(address)" <ADDRESS_TO_PASS_INTO_CONSTRUCTOR>
  • Then use that cast output to add --constructor-args to the end of the forge verify-contract command.

For Ethereum L1 or L1 testnets use the Etherscan API key: https://etherscan.io/myapikey

For L2s (e.g. Base) or L2 testnets use a Basescan API key (but still call it --etherscan-api-key in the command): https://basescan.org/myapikey

Last updated