138 lines
2.9 KiB
Markdown
138 lines
2.9 KiB
Markdown
|
|
# Foundry Configuration Fix
|
||
|
|
|
||
|
|
**Date**: 2025-12-11
|
||
|
|
**Issue**: Warnings about unknown `etherscan` and `rpc_url` config in profiles
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## ❌ Problem
|
||
|
|
|
||
|
|
Foundry was showing warnings:
|
||
|
|
```
|
||
|
|
Warning: Found unknown `etherscan` config for profile `mainnet` defined in foundry.toml.
|
||
|
|
Warning: Found unknown `rpc_url` config for profile `mainnet` defined in foundry.toml.
|
||
|
|
```
|
||
|
|
|
||
|
|
These warnings appeared for all network profiles (mainnet, cronos, bsc, polygon, gnosis, avalanche, base, arbitrum, optimism).
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## ✅ Solution
|
||
|
|
|
||
|
|
Foundry profiles don't support `rpc_url` and `etherscan` as direct keys. These configurations should be referenced via command-line flags instead.
|
||
|
|
|
||
|
|
**Removed**: Profile sections with `rpc_url` and `etherscan` keys
|
||
|
|
**Kept**: `[rpc_endpoints]` and `[etherscan]` sections (these are correct)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 📋 Correct Usage
|
||
|
|
|
||
|
|
### RPC Endpoints
|
||
|
|
|
||
|
|
Reference RPC endpoints by name from the `[rpc_endpoints]` section:
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# Use mainnet RPC
|
||
|
|
forge script ... --rpc-url mainnet
|
||
|
|
|
||
|
|
# Use polygon RPC
|
||
|
|
forge script ... --rpc-url polygon
|
||
|
|
```
|
||
|
|
|
||
|
|
### Etherscan API Keys
|
||
|
|
|
||
|
|
Reference etherscan configs by name and pass the API key:
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# For mainnet
|
||
|
|
forge verify-contract ... --etherscan-api-key $ETHERSCAN_API_KEY
|
||
|
|
|
||
|
|
# For polygon
|
||
|
|
forge verify-contract ... --etherscan-api-key $POLYGONSCAN_API_KEY
|
||
|
|
```
|
||
|
|
|
||
|
|
Or use the `--chain` flag with the etherscan config name:
|
||
|
|
|
||
|
|
```bash
|
||
|
|
forge verify-contract ... --chain polygon --etherscan-api-key $POLYGONSCAN_API_KEY
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 🔧 Configuration Structure
|
||
|
|
|
||
|
|
### Correct `foundry.toml` Structure
|
||
|
|
|
||
|
|
```toml
|
||
|
|
[rpc_endpoints]
|
||
|
|
mainnet = "${ETHEREUM_MAINNET_RPC}"
|
||
|
|
polygon = "${POLYGON_RPC_URL}"
|
||
|
|
# ... etc
|
||
|
|
|
||
|
|
[etherscan]
|
||
|
|
mainnet = { key = "${ETHERSCAN_API_KEY}" }
|
||
|
|
polygon = { key = "${POLYGONSCAN_API_KEY}", chain = "polygon" }
|
||
|
|
# ... etc
|
||
|
|
|
||
|
|
# Profiles should NOT contain rpc_url or etherscan keys
|
||
|
|
[profile.default]
|
||
|
|
# ... compiler settings
|
||
|
|
```
|
||
|
|
|
||
|
|
### Removed Profile Sections
|
||
|
|
|
||
|
|
The following profile sections were removed (they caused warnings):
|
||
|
|
|
||
|
|
```toml
|
||
|
|
# ❌ REMOVED - Not supported by Foundry
|
||
|
|
[profile.mainnet]
|
||
|
|
rpc_url = "mainnet"
|
||
|
|
etherscan = "mainnet"
|
||
|
|
chain_id = 1
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 📝 Chain IDs Reference
|
||
|
|
|
||
|
|
For reference when using `--chain-id` flag:
|
||
|
|
|
||
|
|
- **mainnet**: 1
|
||
|
|
- **cronos**: 25
|
||
|
|
- **bsc**: 56
|
||
|
|
- **polygon**: 137
|
||
|
|
- **gnosis**: 100
|
||
|
|
- **avalanche**: 43114
|
||
|
|
- **base**: 8453
|
||
|
|
- **arbitrum**: 42161
|
||
|
|
- **optimism**: 10
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## ✅ Verification
|
||
|
|
|
||
|
|
After the fix, Foundry commands should run without warnings:
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# Should show no warnings
|
||
|
|
forge script script/DeployMainnetTether.s.sol --rpc-url mainnet --dry-run
|
||
|
|
|
||
|
|
# Should show no warnings
|
||
|
|
forge verify-contract ... --etherscan-api-key $ETHERSCAN_API_KEY
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 📚 Additional Resources
|
||
|
|
|
||
|
|
- [Foundry Book - Configuration](https://book.getfoundry.sh/reference/config)
|
||
|
|
- [Foundry Book - Scripts](https://book.getfoundry.sh/reference/forge/forge-script)
|
||
|
|
- [Foundry Book - Verify](https://book.getfoundry.sh/reference/forge/forge-verify-contract)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
**Last Updated**: 2025-12-11
|
||
|
|
**Status**: ✅ Fixed
|
||
|
|
|