2025-12-12 14:57:48 -08:00
|
|
|
# Explorer API Keys Setup Guide
|
|
|
|
|
|
|
|
|
|
**Purpose**: Contract verification on blockchain explorers
|
|
|
|
|
**Status**: Optional but recommended
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 🔑 Required API Keys
|
|
|
|
|
|
|
|
|
|
### Chains with Contract Verification
|
|
|
|
|
|
|
|
|
|
| Chain | Explorer | API Key Variable | Get API Key |
|
|
|
|
|
|-------|----------|-----------------|-------------|
|
|
|
|
|
| **Ethereum Mainnet** | Etherscan | `ETHERSCAN_API_KEY` | https://etherscan.io/apis |
|
|
|
|
|
| **BSC** | BscScan | `BSCSCAN_API_KEY` | https://bscscan.com/apis |
|
|
|
|
|
| **Polygon** | Polygonscan | `POLYGONSCAN_API_KEY` | https://polygonscan.com/apis |
|
|
|
|
|
| **Avalanche** | Snowtrace | `SNOWTRACE_API_KEY` | https://snowtrace.io/apis |
|
|
|
|
|
| **Base** | Basescan | `BASESCAN_API_KEY` | https://basescan.org/apis |
|
|
|
|
|
| **Arbitrum** | Arbiscan | `ARBISCAN_API_KEY` | https://arbiscan.io/apis |
|
|
|
|
|
| **Optimism** | Optimistic Etherscan | `OPTIMISTIC_ETHERSCAN_API_KEY` | https://optimistic.etherscan.io/apis |
|
2026-03-02 12:14:09 -08:00
|
|
|
| **Cronos** | Cronos Explorer | `CRONOSCAN_API_KEY` | https://explorer.cronos.org/register (My API Keys) |
|
2025-12-12 14:57:48 -08:00
|
|
|
| **Gnosis** | Gnosisscan | `GNOSISSCAN_API_KEY` | https://gnosisscan.io/apis |
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 📝 How to Get API Keys
|
|
|
|
|
|
|
|
|
|
### 1. Create Account
|
|
|
|
|
- Visit the explorer website
|
|
|
|
|
- Sign up for a free account
|
|
|
|
|
- Verify your email
|
|
|
|
|
|
|
|
|
|
### 2. Generate API Key
|
|
|
|
|
- Go to API section (usually under "Account" or "API")
|
|
|
|
|
- Click "Create API Key"
|
|
|
|
|
- Give it a name (e.g., "Foundry Deployment")
|
|
|
|
|
- Copy the API key
|
|
|
|
|
|
|
|
|
|
### 3. Add to `.env`
|
|
|
|
|
```bash
|
|
|
|
|
ETHERSCAN_API_KEY=your_actual_api_key_here
|
|
|
|
|
BSCSCAN_API_KEY=your_actual_api_key_here
|
|
|
|
|
POLYGONSCAN_API_KEY=your_actual_api_key_here
|
|
|
|
|
SNOWTRACE_API_KEY=your_actual_api_key_here
|
|
|
|
|
BASESCAN_API_KEY=your_actual_api_key_here
|
|
|
|
|
ARBISCAN_API_KEY=your_actual_api_key_here
|
|
|
|
|
OPTIMISTIC_ETHERSCAN_API_KEY=your_actual_api_key_here
|
|
|
|
|
CRONOSCAN_API_KEY=your_actual_api_key_here
|
|
|
|
|
GNOSISSCAN_API_KEY=your_actual_api_key_here
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## ⚠️ Important Notes
|
|
|
|
|
|
|
|
|
|
1. **Free Tier Limits**: Most explorers offer free API keys with rate limits
|
|
|
|
|
- Usually sufficient for deployment and verification
|
|
|
|
|
- Check limits on each explorer's website
|
|
|
|
|
|
|
|
|
|
2. **Security**:
|
|
|
|
|
- Never commit API keys to version control
|
|
|
|
|
- Keep `.env` file secure
|
|
|
|
|
- Rotate keys periodically
|
|
|
|
|
|
|
|
|
|
3. **Optional but Recommended**:
|
|
|
|
|
- Contract verification helps users trust your contracts
|
|
|
|
|
- Makes contract interaction easier
|
|
|
|
|
- Required for some DeFi protocols
|
|
|
|
|
|
|
|
|
|
4. **Without API Keys**:
|
|
|
|
|
- Deployment will still work
|
|
|
|
|
- Contracts won't be automatically verified
|
|
|
|
|
- Manual verification possible later
|
|
|
|
|
|
2026-03-02 12:14:09 -08:00
|
|
|
5. **Cronos**:
|
|
|
|
|
- Use Cronos Explorer (explorer.cronos.org), not cronoscan.com
|
|
|
|
|
- Forge verification requires manual UI: https://explorer.cronos.org/verifyContract
|
|
|
|
|
- See [CRONOS_EXPLORER_OPERATIONS.md](../04-configuration/CRONOS_EXPLORER_OPERATIONS.md) for confirmation and API usage
|
|
|
|
|
|
2025-12-12 14:57:48 -08:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## ✅ Verification
|
|
|
|
|
|
|
|
|
|
After adding API keys, test with:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# Test Ethereum Mainnet (if you have a deployed contract)
|
|
|
|
|
forge verify-contract \
|
|
|
|
|
--chain-id 1 \
|
|
|
|
|
--num-of-optimizations 200 \
|
|
|
|
|
<CONTRACT_ADDRESS> \
|
|
|
|
|
<CONTRACT_NAME> \
|
|
|
|
|
$ETHERSCAN_API_KEY
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 🚀 Deployment with Verification
|
|
|
|
|
|
|
|
|
|
When deploying with `--verify` flag, Foundry will automatically use the API keys:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
forge script script/DeployAll.s.sol:DeployAll \
|
|
|
|
|
--rpc-url mainnet \
|
|
|
|
|
--private-key $PRIVATE_KEY \
|
|
|
|
|
--broadcast \
|
|
|
|
|
--verify \
|
|
|
|
|
-vvvv
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The `--verify` flag uses the API keys from `.env` automatically.
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
**Status**: Optional - Deployment works without API keys, but verification requires them.
|
|
|
|
|
|