Skip to main content

Accounts

On several blockchains, cryptocurrency wallets (or accounts) can be established and represented in various ways. It is crucial to know that accounts on Humans.ai are designed to be compatible with Ethereum type addresses for developers who interact with account types there, such as when integrating a wallet into their dApp frontend.

Prerequisite Readings

Creating Accounts

phrase (a string of words that can access numerous private keys) can be used  to create a single account.

The main distinction between each of them is that a private key or keystore file only generates one account, aside from having various security measures. By coming up with a mnemonic phrase, you can take control of numerous accounts that are all accessed using the same phrase.

Mnemonic phrase account creation is supported by Cosmos blockchains like Humans.ai, which also allow hierarchical deterministic key generation (HD keys). This spares the user from having to manage several secret passwords when creating accounts on different blockchains.

The mnemonic phrase and a piece of data known as a derivation path are combined to create addresses using HD keys. The derivation paths that different blockchains support can be different. It is crucial to follow that blockchain's unique derivation path in order to access all accounts from a mnemonic phrase.

Representing Accounts

In describing cryptocurrency wallets, the terms account and address are frequently used interchangeably. An account in the Cosmos SDK designates a set of public and private keys (PubKey and PrivKey). The private key, public key, and address are specified by the derivation path.

The application uses addresses in different formats, which can be generated using the PubKey, to identify users and other parties. The bech32 format (for example, human1...) is a typical address format for Cosmos chains. In order to identify the message's sender, addresses are also attached to messages.

The PrivKey is used to create digital signatures that serve as evidence that a message was authorized by an address connected to the PrivKey. The Elliptic Curve Digital Signature Algorithm (ECDSA), a cryptographic technique, is used to transform the PrivKey into a PubKey, which is then compared to the message's address to complete the proof.

Humans.ai Accounts

In order to implement an HD wallet that is compatible with Ethereum type addresses, Humans.ai develops its own unique custom Account type. It complies with EIP84 for full BIP44 pathways and uses Ethereum's ECDSA secp256k1 curve for keys (eth_secp265k1). Contrary to popular belief, this cryptographic curve is not the same as the ECDSA secp256k1 curve used by Bitcoin.

The root HD path for accounts based on Humans.ai is m/44'/60'/0'/0. In contrast to many other Cosmos chains that utilize Coin type 118, Humans.ai employs Coin type 60 to accommodate Ethereum-style accounts (list of coin types).

EthAccount satisfies the AccountI interface from the Cosmos SDK auth module and adds extra fields needed for Ethereum type addresses:

// 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
}

Visit the x/evm module for more details on Ethereum accounts.

Addresses and Public Keys

The BIP-0173 specification specifies a new format for segregated witness output addresses that includes a human-readable portion that indicates the Bech32 usage. The following HRP (human readable prefix) is used by Humans.ai as the basis HRP:

NetworkMainnetTestnet
Humans.aihumanhuman

For the Addresses and PubKeys offered by default on Humans.ai, there are three basic types of HRP:

  • Addresses and Keys for accounts, that allow users to be identified (like the sender of a message). Utilizing the eth_secp256k1 curve, they are produced.
  • Addresses and Keys for validator operators, which specify the validators' operators. Utilizing the eth_secp256k1 curve, they are produced.
  • Addresses and Keys for consensus nodes, which identify the validator nodes participating in consensus. They are derived using the ed25519 curve.
Address bech32 PrefixPubkey bech32 PrefixCurveAddress byte lengthPubkey byte length
Accountshumanhumanpubeth_secp256k12033 (compressed)
Validator Operatorhumanvaloperhumanvaloperpubeth_secp256k12033 (compressed)
Consensus Nodeshumanvalconshumanvalconspubed255192032

Address formats for clients

For interoperability with Ethereum's Web3 tools, EthAccount can be represented in both Bech32 (human1...) and hex (0x...) forms.

For queries and transactions made using the Cosmos-SDK through CLI and REST clients, the Bech32 format is the default. On the other side, the hex format represents a Cosmos sdk.AccAddress as an Ethereum common.Address.

  • Address (Bech32): human19ugs5jrk79srm2x0n75ulh0twh8lw3g495ceyj
  • Address (EIP55 Hex): 0x2F110A4876f1603da8cF9FA9cfddEb75cFF74515
  • Compressed Public Key: {"@type":"/ethermint.crypto.v1.ethsecp256k1.PubKey","key":"G4pLREfM08dQ9aPcR0IhS2blaB6pPUaPmNfBK4U1A"}

Address conversion

To translate an address between hex and bech32 formats, use the humansd debug addr <address> command. For instance:

Bech32
 $ humansd debug addr human19ugs5jrk79srm2x0n75ulh0twh8lw3g495ceyj
Address: [20 87 74 109 255 45 223 158 7 130 139 67 69 211 4 9 25 175 86 82]
Address (hex): 14574A6DFF2DDF9E07828B4345D3040919AF5652
Bech32 Acc: human19ugs5jrk79srm2x0n75ulh0twh8lw3g495ceyj
Bech32 Val: humanvaloper1x4p98e0l1a7tq4j6p9c0e0p8z74jjn4d6nn
Hex
 $ humansd debug addr 14574A6DFF2DDF9E07828B4345D3040919AF5652
Address: [20 87 74 109 255 45 223 158 7 130 139 67 69 211 4 9 25 175 86 82]
Address (hex): 14574A6DFF2DDF9E07828B4345D3040919AF5652
Bech32 Acc: human19ugs5jrk79srm2x0n75ulh0twh8lw3g495ceyj
Bech32 Val: humanvaloper1x4p98e0l1a7tq4j6p9c0e0p8z74jjn4d6nn

Key output

tip

Only Bech32-formatted addresses and public keys are supported by the Cosmos SDK Keyring output (also known as humansd keys).

With the flag --bech type> (acc|val|cons), we can utilize the keys show command of humansd. in order to get the addresses and keys stated above.

Accounts
 $ humansd keys show dev0 --bech acc
- name: dev0
type: local
address: human19ugs5jrk79srm2x0n75ulh0twh8lw3g495ceyj
pubkey: '{"@type":"/ethermint.crypto.v1.ethsecp256k1.PubKey","key":"jCNscnnDB+hkByIJo/4lViJ3sDTzNfBPKC73cZ4D2K2Y"}'
mnemonic: ""
Validator
 $ humansd keys show dev0 --bech val
- name: dev0
type: local
address: humanvaloper1x4p98e0l1a7tq4j6p9c0e0p8z74jjn4d6nn
pubkey: '{"@type":"/ethermint.crypto.v1.ethsecp256k1.PubKey","key":"BdLPnBdeB+hkByIJo/4lZiVUgXTzNfBPKC73cZ4K1YD2"}'
mnemonic: ""
Consensus
 $ humansd keys show dev0 --bech cons
- name: dev0
type: local
address: humanvalcons1k2v75f0l3a5tq8j76p9c0e0p9z74jjn4d6nn
pubkey: '{"@type":"/ethermint.crypto.v1.ethsecp256k1.PubKey","key":"ABdLPnBdeB+hLykFQxum96JkSOoTemrXD0tFaFQ14lZiVUg"}'
mnemonic: ""

Querying an Account

You can use the CLI, gRPC, or JSON-RPC to query an account address.

Command Line Interface

# NOTE: the --output (-o) flag will define the output format in JSON or YAML (text)
humansd q auth account $(humansd keys show dev0 -a) -o text

'@type': /ethermint.types.v1.EthAccount
base_account:
account_number: "0"
address: human19ugs5jrk79srm2x0n75ulh0twh8lw3g495ceyj
pub_key:
'@type': /ethermint.crypto.v1.ethsecp256k1.PubKey
key: jCNscnnDB+hkByIJo/4lViJ3sDTzNfBPKC73cZ4D2K2Y
sequence: "1"
code_hash: 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470

Cosmos gRPC and REST

# GET /cosmos/auth/v1beta1/accounts/{address}
curl -X GET "http://localhost:10337/cosmos/auth/v1beta1/accounts/human19ugs5jrk79srm2x0n75ulh0twh8lw3g495ceyj" -H "accept: application/json"

JSON-RPC

Use the JSON-RPC 'eth_accounts' or 'personal_listAccounts' endpoints to access the Ethereum hex address using Web3:

# query against a local node
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}' -H "Content-Type: application/json" http://localhost:8545

curl -X POST --data '{"jsonrpc":"2.0","method":"personal_listAccounts","params":[],"id":1}' -H "Content-Type: application/json" http://localhost:8545