Cosmos EVM 中的账户被设计为同时兼容 Ethereum 和 Cosmos SDK 工具链。对于需要与账户类型交互的开发者(例如进行钱包集成时),理解这种双重表示方式至关重要。 参考资料:Cosmos SDK 账户、Ethereum 账户

账户结构

在 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)
自定义的 EthAccount 满足 Cosmos SDK 的 AccountI 接口,并额外包含 Ethereum 特有字段(账户 keeper 的实现可参见 x/vm/types 接口):
// EthAccountI represents the interface of an EVM compatible account
type EthAccountI interface {
    authtypes.AccountI

    // EthAddress returns the ethereum Address representation of the AccAddress
    EthAddress() common.Address

    // CodeHash is the keccak256 hash of the contract code (if any)
    GetCodeHash() common.Hash

    // SetCodeHash sets the code hash to the account fields
    SetCodeHash(code common.Hash) error

    // Type returns the type of Ethereum Account (EOA or Contract)
    Type() int8
}
EIP-7702 支持:Cosmos EVM 支持 EIP-7702 代码委托,允许 EOA 通过 SetCodeHash 功能临时将代码执行委托给智能合约。

地址格式

Bech32 与十六进制表示

EthAccount 可以同时表示为 Bech32(cosmos1...)和十六进制(0x...)格式,以兼容两个生态系统。 Bech32(Cosmos SDK 默认格式):
cosmos1z3t55m0l9h0eupuz3dp5t5cypyv674jj7mz2jw
EIP-55 Hex(兼容 Ethereum):
0x91defC7fE5603DFA8CC9B655cF5772459BF10c6f
公钥:
{
  "@type": "/ethermint.crypto.v1.ethsecp256k1.PubKey",
  "key": "AsV5oddeB+hkByIJo/4lZiVUgXTzNfBPKC73cZ4K1YD2"
}

地址类型

BIP-0173 定义了带有人类可读前缀的 Bech32 格式: 用户账户(eth_secp256k1):
  • 地址:cosmos 前缀,20 字节
  • 公钥:cosmospub 前缀,33 字节(压缩格式)
验证者操作账户(eth_secp256k1):
  • 地址:cosmosvaloper 前缀,20 字节
  • 公钥:cosmosvaloperpub 前缀,33 字节(压缩格式)
共识节点(ed25519):
  • 地址:cosmosvalcons 前缀,20 字节
  • 公钥:cosmosvalconspub 前缀,32 字节

地址转换

可使用 CLI 在不同格式之间进行转换:
# Bech32 to Hex
$ evmd debug addr cosmos1z3t55m0l9h0eupuz3dp5t5cypyv674jj7mz2jw

Address (hex): 14574A6DFF2DDF9E07828B4345D3040919AF5652
Bech32 Acc: cosmos1z3t55m0l9h0eupuz3dp5t5cypyv674jj7mz2jw
Bech32 Val: cosmosvaloper1z3t55m0l9h0eupuz3dp5t5cypyv674jjn4d6nn

查询账户

可通过 CLI、REST 或 JSON-RPC 查询账户: CLI:
evmd q auth account $(evmd keys show dev0 -a) -o json
REST API:
curl -X GET "http://localhost:10337/cosmos/auth/v1beta1/accounts/{address}"
JSON-RPC:eth_accounts、personal_listAccounts

相关文档


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 custom Account 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 type 60 for Ethereum compatibility)
The custom EthAccount satisfies the Cosmos SDK AccountI interface with additional Ethereum-specific fields (see x/vm/types interfaces for the account keeper implementation):
// EthAccountI represents the interface of an EVM compatible account
type EthAccountI interface {
    authtypes.AccountI

    // EthAddress returns the ethereum Address representation of the AccAddress
    EthAddress() common.Address

    // CodeHash is the keccak256 hash of the contract code (if any)
    GetCodeHash() common.Hash

    // SetCodeHash sets the code hash to the account fields
    SetCodeHash(code common.Hash) error

    // Type returns the type of Ethereum Account (EOA or Contract)
    Type() int8
}
EIP-7702 Support: Cosmos EVM supports EIP-7702 code delegation, allowing EOAs to temporarily delegate code execution to smart contracts through the 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):
cosmos1z3t55m0l9h0eupuz3dp5t5cypyv674jj7mz2jw
EIP-55 Hex (Ethereum compatibility):
0x91defC7fE5603DFA8CC9B655cF5772459BF10c6f
Public Key:
{
  "@type": "/ethermint.crypto.v1.ethsecp256k1.PubKey",
  "key": "AsV5oddeB+hkByIJo/4lZiVUgXTzNfBPKC73cZ4K1YD2"
}

Address Types

BIP-0173 defines Bech32 format with human-readable prefixes: User Accounts (eth_secp256k1):
  • Address: cosmos prefix, 20 bytes
  • Pubkey: cosmospub prefix, 33 bytes (compressed)
Validator Operators (eth_secp256k1):
  • Address: cosmosvaloper prefix, 20 bytes
  • Pubkey: cosmosvaloperpub prefix, 33 bytes (compressed)
Consensus Nodes (ed25519):
  • Address: cosmosvalcons prefix, 20 bytes
  • Pubkey: cosmosvalconspub prefix, 32 bytes

Address Conversion

Convert between formats using the CLI:
# Bech32 to Hex
$ evmd debug addr cosmos1z3t55m0l9h0eupuz3dp5t5cypyv674jj7mz2jw

Address (hex): 14574A6DFF2DDF9E07828B4345D3040919AF5652
Bech32 Acc: cosmos1z3t55m0l9h0eupuz3dp5t5cypyv674jj7mz2jw
Bech32 Val: cosmosvaloper1z3t55m0l9h0eupuz3dp5t5cypyv674jjn4d6nn

Querying Accounts

Query accounts via CLI, REST, or JSON-RPC: CLI:
evmd q auth account $(evmd keys show dev0 -a) -o json
REST API:
curl -X GET "http://localhost:10337/cosmos/auth/v1beta1/accounts/{address}"
JSON-RPC: eth_accounts, personal_listAccounts
  • x/vm Module - Ethereum account implementation details