forge-verify
v1.0.1
Published
A utility for verifying Foundry/Forge compiled smart contracts on Etherscan
Downloads
17
Maintainers
Readme
Forge-Verify
A utility for verifying Foundry/Forge compiled smart contracts on Etherscan.
Description
Forge-Verify is a command-line tool that simplifies the process of verifying smart contracts deployed with Foundry on Etherscan. It automatically extracts necessary information from your Foundry deployment files and submits verification requests to Etherscan through their API.
Features
- Automatic verification of all contracts in a deployment
- Support for verifying specific contracts
- Automatic detection of compiler versions and optimizer settings
- Support for constructor arguments
- Flexible command-line interface
- No configuration files needed
Installation
# Install globally
npm install -g forge-verify
# Or use with npx
npx forge-verifyPrerequisites
- Node.js >= 14.0.0
- Foundry/Forge toolchain installed
- An Etherscan API key
- RPC URL for the target network
Usage
Basic Usage
Verify all contracts from the latest deployment by providing the required parameters:
forge-verify --chainId=1 --etherscan=YOUR_API_KEY --rpcUrl=YOUR_RPC_URLCommand Line Options
Usage: forge-verify [options]
Options:
-c, --chainId The chain ID of the network [string] [required]
-e, --etherscan Your Etherscan API key [string] [required]
-r, --rpcUrl RPC URL for the network [string] [required]
-t, --target Target deployment by block number [string] [default: "latest"]
-s, --script Deployment script name [string]
-h, --help Show help [boolean]
--contracts Comma-separated list of specific contracts to verify [string]
Examples:
forge-verify --chainId=1 --etherscan=YOUR_API_KEY --rpcUrl=YOUR_RPC_URL Verify all contracts from the latest deployment
forge-verify --chainId=1 --etherscan=YOUR_API_KEY --rpcUrl=YOUR_RPC_URL --contracts=MyToken,Vault Verify specific contractsExamples
Verify a specific deployment using block number:
forge-verify --chainId=1 --etherscan=YOUR_API_KEY --rpcUrl=YOUR_RPC_URL --target=15784932Verify specific contracts:
forge-verify --chainId=1 --etherscan=YOUR_API_KEY --rpcUrl=YOUR_RPC_URL --contracts=MyToken,VaultSpecify deployment script:
forge-verify --chainId=1 --etherscan=YOUR_API_KEY --rpcUrl=YOUR_RPC_URL --script=Deploy.s.solUse with a different network (Goerli testnet):
forge-verify --chainId=5 --etherscan=YOUR_API_KEY --rpcUrl=YOUR_GOERLI_RPC_URLHow It Works
- Reads deployment data from Foundry broadcast files
- Extracts contract addresses and constructor arguments
- Determines compiler version and optimizer settings from contract artifacts
- Submits verification requests to Etherscan with proper parameters
- Monitors verification status until completion
Troubleshooting
Error: No deploy scripts found in the script directory
- Ensure you have at least one script file in the
./scriptdirectory
- Ensure you have at least one script file in the
Error: Specified contract not found in deployment data
- Check that the contract name matches exactly what's in your deployment script
- Verify that the contract was deployed in the targeted deployment run
Verification failure
- Check that your Etherscan API key is valid
- Ensure the contract was deployed on the specified chain
- Verify that the exact compiler version used for deployment is available
License
Apache License 2.0 - See LICENSE for details.
Contributing
Contributions are welcome! Feel free to submit issues or pull requests.
Programmatic Usage
You can also use forge-verify programmatically in your Node.js applications:
const { verifyContracts } = require('forge-verify');
// Example usage
const main = async () => {
try {
await verifyContracts({
chainId: '1',
etherscan: 'YOUR_ETHERSCAN_API_KEY',
rpcUrl: 'YOUR_RPC_URL',
target: 'latest',
script: 'Deploy.s.sol',
contracts: 'MyToken,Vault' // Optional
});
console.log('Verification completed successfully!');
} catch (error) {
console.error('Error verifying contracts:', error);
}
};
main();