账户结构
在 Cosmos SDK 中,账户由一对公钥(PubKey)和私钥(PrivKey)构成。派生路径决定了私钥、公钥和地址的生成结果。 Cosmos 区块链支持使用助记词,通过分层确定性密钥生成(HD keys)创建账户。HD keys 会将助记词与派生路径结合来生成地址。EVM 账户
Cosmos EVM 定义了一个自定义Account 类型,通过以下方式实现与 Ethereum 地址兼容的 HD 钱包:
- 使用 Ethereum 的 ECDSA secp256k1 曲线(
eth_secp265k1) - 使用 EIP84 以支持完整的 BIP44 路径
- 根 HD 路径:
m/44'/60'/0'/0(币种类型60,用于兼容 Ethereum)
AccountI 接口,并额外包含 Ethereum 特有字段(账户 keeper 的实现可参见 x/vm/types 接口):
SetCodeHash 功能临时将代码执行委托给智能合约。
地址格式
Bech32 与十六进制表示
EthAccount 可以同时表示为 Bech32(cosmos1...)和十六进制(0x...)格式,以兼容两个生态系统。
Bech32(Cosmos SDK 默认格式):
地址类型
BIP-0173 定义了带有人类可读前缀的 Bech32 格式: 用户账户(eth_secp256k1):
- 地址:
cosmos前缀,20 字节 - 公钥:
cosmospub前缀,33 字节(压缩格式)
eth_secp256k1):
- 地址:
cosmosvaloper前缀,20 字节 - 公钥:
cosmosvaloperpub前缀,33 字节(压缩格式)
ed25519):
- 地址:
cosmosvalcons前缀,20 字节 - 公钥:
cosmosvalconspub前缀,32 字节
地址转换
可使用 CLI 在不同格式之间进行转换:查询账户
可通过 CLI、REST 或 JSON-RPC 查询账户: CLI:eth_accounts、personal_listAccounts
相关文档
- x/vm 模块 - Ethereum 账户实现细节
Accounts in Cosmos EVM are designed for compatibility with both Ethereum and Cosmos SDK tooling. For developers interfacing with account types (e.g., during wallet integration), understanding the dual representation is essential. References: Cosmos SDK Accounts, Ethereum Accounts
Account Structure
In the Cosmos SDK, an account designates a pair of public key (PubKey) and private key (PrivKey). The derivation path defines what the private key, public key, and address would be. Cosmos blockchains support creating accounts with mnemonic phrases using hierarchical deterministic key generation (HD keys). HD keys generate addresses by combining the mnemonic phrase with a derivation path.EVM Accounts
Cosmos EVM defines a customAccount type implementing an HD wallet compatible with Ethereum addresses using:
- Ethereum’s ECDSA secp256k1 curve (
eth_secp265k1) - EIP84 for full BIP44 paths
- Root HD path:
m/44'/60'/0'/0(Coin type60for Ethereum compatibility)
AccountI interface with additional Ethereum-specific fields (see x/vm/types interfaces for the account keeper implementation):
SetCodeHash functionality.
Address Formats
Bech32 and Hex Representations
EthAccount can be represented in both Bech32 (cosmos1...) and hex (0x...) formats for compatibility with both ecosystems.
Bech32 (default for Cosmos SDK):
Address Types
BIP-0173 defines Bech32 format with human-readable prefixes: User Accounts (eth_secp256k1):
- Address:
cosmosprefix, 20 bytes - Pubkey:
cosmospubprefix, 33 bytes (compressed)
eth_secp256k1):
- Address:
cosmosvaloperprefix, 20 bytes - Pubkey:
cosmosvaloperpubprefix, 33 bytes (compressed)
ed25519):
- Address:
cosmosvalconsprefix, 20 bytes - Pubkey:
cosmosvalconspubprefix, 32 bytes
Address Conversion
Convert between formats using the CLI:Querying Accounts
Query accounts via CLI, REST, or JSON-RPC: CLI:eth_accounts, personal_listAccounts
Related Documentation
- x/vm Module - Ethereum account implementation details