你可以查阅 chainlist.org 上现有的 EVM Chain ID,确保你选择的 ID 尚未被使用。
双重 Chain ID 体系
Cosmos EVM 需要 两个完全独立的 Chain ID,以同时与 Cosmos SDK 生态和 Ethereum 生态保持完整兼容性。1. Cosmos Chain ID(字符串)
Cosmos Chain ID 是一个字符串标识符,用于:- CometBFT 共识引擎
- IBC(跨链通信)协议
- 原生 Cosmos SDK 交易
- 链升级与治理
"mychain-1"、"testnet-2")
示例:
2. EVM Chain ID(整数)
EVM Chain ID 是一个整数,用于:- Ethereum 交易(EIP-155 重放保护)
- MetaMask 和其他 Ethereum 钱包
- 智能合约部署
- EVM 工具链(Hardhat、Foundry 等)
配置
在搭建你的链时,必须同时配置这两个 Chain ID:在应用代码中
在 Genesis 配置中
Cosmos Chain ID 在genesis.json 中设置:
重要注意事项
EVM Chain ID 选择指南
选择你的 EVM Chain ID 时:- 检查可用性:确认你选择的 ID 尚未在 chainlist.org 上被使用
- 避免冲突:不要使用知名的 Chain ID(例如 Ethereum 主网的 1、Polygon 的 137 等)
- 选择任意可用整数:没有强制的取值范围或格式,只需选择一个未被使用的整数即可
链升级
与传统 Cosmos 链会在升级时变更其 Chain ID(例如从
cosmoshub-4 变为 cosmoshub-5)不同,EVM Chain ID 在升级过程中必须始终保持 不变,以维持与已部署智能合约和现有钱包的兼容性。故障排查
常见问题
-
“Chain ID 不匹配”错误
- 原因:在需要 EVM Chain ID 的地方使用了 Cosmos Chain ID(或反之)
- 解决方案:确保在每个上下文中使用正确类型的 Chain ID
-
MetaMask 连接失败
- 原因:钱包配置中的 EVM Chain ID 不正确
- 解决方案:使用整数类型的 EVM Chain ID,而不是字符串类型的 Cosmos Chain ID
-
IBC 转账失败
- 原因:在 IBC 操作中使用了 EVM Chain ID
- 解决方案:IBC 始终使用 Cosmos Chain ID(字符串格式)
-
智能合约部署问题
- 原因:EIP-155 重放保护使用了错误的 Chain ID
- 解决方案:确保你的 EVM Chain ID 与链上的配置一致
验证命令
要验证你的 Chain ID 是否已正确配置:You can look up existing EVM Chain IDs by referring to chainlist.org to ensure your chosen ID is not already in use.
Dual Chain ID System
Cosmos EVM requires two completely independent chain IDs to maintain full compatibility with both the Cosmos SDK and Ethereum ecosystems.1. Cosmos Chain ID (String)
The Cosmos Chain ID is a string identifier used by:- CometBFT consensus engine
- IBC (Inter-Blockchain Communication) protocol
- Native Cosmos SDK transactions
- Chain upgrades and governance
"mychain-1", "testnet-2")
Example:
2. EVM Chain ID (Integer)
The EVM Chain ID is an integer used by:- Ethereum transactions (EIP-155 replay protection)
- MetaMask and other Ethereum wallets
- Smart contract deployments
- EVM tooling (Hardhat, Foundry, etc.)
Configuration
Both chain IDs must be configured when setting up your chain:In Your Application Code
In Genesis Configuration
The Cosmos Chain ID is set ingenesis.json:
Important Considerations
EVM Chain ID Guidelines
When selecting your EVM Chain ID:- Check availability: Verify your chosen ID is not already in use on chainlist.org
- Avoid conflicts: Don’t use well-known chain IDs (1 for Ethereum mainnet, 137 for Polygon, etc.)
- Choose any available integer: There are no required ranges or formats - simply pick any integer not in use
Chain Upgrades
Unlike traditional Cosmos chains that change their chain ID during upgrades (e.g.,
cosmoshub-4 to cosmoshub-5), the EVM Chain ID must remain constant across upgrades to maintain compatibility with deployed smart contracts and existing wallets.Troubleshooting
Common Issues
-
“Chain ID mismatch” errors
- Cause: Using Cosmos Chain ID where EVM Chain ID is expected (or vice versa)
- Solution: Ensure you’re using the correct type of chain ID for each context
-
MetaMask connection failures
- Cause: Incorrect EVM Chain ID in wallet configuration
- Solution: Use the integer EVM Chain ID, not the string Cosmos Chain ID
-
IBC transfer failures
- Cause: Using EVM Chain ID for IBC operations
- Solution: IBC always uses the Cosmos Chain ID (string format)
-
Smart contract deployment issues
- Cause: EIP-155 replay protection using wrong chain ID
- Solution: Ensure your EVM Chain ID matches what’s configured in the chain