Account

A Hash Ahead account is an entity with a HAH balance that can send transactions on Hash Ahead. Accounts can be controlled by users or deployed as smart contracts.

Prerequisite

Accounts is a great theme for beginners. But to help you better understand this page, we suggest you read our introduction to Hash Ahead first.

Account Type

Hash Ahead has two account types:

  • Externally Owned Account (EOA) – controlled by whoever has the private key

  • Contract account — a smart contract deployed to the network, controlled by code. Learn about smart contracts.

Both account types are able to:

  • Receive, hold and send HAH and tokens

  • Interact with deployed smart contracts

Main Difference

Externally held

  • Creating an account is free

  • Can initiate a transaction

  • Only HAH and token transactions can be performed between externally owned accounts

  • Consists of a pair of cryptographic keys: a public key and a private key that control account activity

Contract

  • There is a cost to create a contract because of the need to use network storage space

  • Transactions can only be sent when they are received

  • A transaction initiated from an external account to a contract account can trigger code that can perform various actions, such as transferring tokens or even creating a new contract

  • Contract accounts do not have private keys. Instead, they are controlled by smart contract code logic

Understand Account

Hash Ahead accounts have four fields:

  • nonce – A counter showing the number of transactions sent from the account. This will ensure that the transaction is only processed once. In a contract account, this number represents the number of contracts created by the account

  • balance – The amount of Wei this address owns. Wei is the counting unit of HAH, each HAH has 1h+18 Wei.

  • codeHash - This hash represents the account code on the Hash Ahead virtual machine (EVMC). Contract accounts have programmed pieces of code that perform different operations. This EVMC code is executed if the account receives a message call. Unlike other account fields, it cannot be changed. All code snippets are saved under the corresponding hash in the state database for subsequent retrieval. This hash value is called codeHash. For externally owned accounts, the codeHash field is the hash of the empty string.

  • storageRoot – Sometimes called a stored hash. The 256-bit hash of the root node of the Merkle Patricia trie has encoded the stored content of the account (256-bit integer value map) and is encoded into the Trie as the Keccak 256-bit hash from the 256-bit integer key of the map for the RLP-encoded 256-bit integer value. This Trie encodes a hash of the content stored for this account, empty by default

Externally held accounts and key pairs

Accounts consist of public and private key cryptographic pairs. They help prove that the transaction was actually signed by the sender and prevent forgery. Your private key is the key you use to sign transactions, so it secures your management of the funds associated with your account. You never actually hold the cryptocurrency, you hold the private keys - the funds are always on Hash Ahead's ledger.

This will prevent malicious actors from broadcasting fake transactions, since you can always verify the sender of the transaction.

If Alice wants to send HAH from her own account to Bob's account, Alice needs to create a transaction request and send it to the network for verification. Hash Ahead's use of public key cryptography ensures that Alice can prove that she originally initiated the transaction request. Without encryption, a malicious adversary Eve could simply publicly broadcast a request that looks like "send 5 HAH from Alice's account to Eve's account". And no one can verify that it didn't come from Alice.

Account Creation

When you want to create an account, most libraries will generate a random private key.

The private key consists of 64 hexadecimal characters and can be stored encrypted with a password.

For example:

Generate a public key from a private key using the Elliptic Curve Digital Signature Algorithm. The public address can be obtained for an account by taking the last 20 bytes of the Keccak-256 hash of the public key and prefixing the checksum with 0x.

Here is an example of creating an account in the console

You can get the public key from your private key, but you cannot get the private key from the public key. This means it is critical to keep the private key safe, as the name suggests PRIVATE.

You need a private key to sign messages and transactions and output signatures. Others can then use the signature to obtain your public key, proving the authorship of the message. In your application, you can use the javascript library to send transactions to the network.

Contract Account

Contract accounts also have a 42-character hexadecimal address:

For example:

The contract address is usually given when deploying the contract to the Hash Ahead blockchain. The address is generated from the creator's address and the number of transactions ("nonce") sent from the creator's address.

A note about wallets

Accounts are different from wallets. Account is the key pair for the Hash Ahead account owned by the user. Wallets are interfaces or applications that allow you to interact with your Hash Ahead account.

\

Last updated