Account

In Chapter 1Introduction to Blockchain Technology, we discussed addresses, an account-like concept, which is used to host balances of BTC. Bitcoin uses the UTOX model to manage the transfer of BTCs between addresses. However, one has to retrieve the entire ledger to find the balance of an address, which is very inconvenient. This inconvenience is due to the fact that Bitcoin does not support an on-chain Turing-complete programming language and it does not have the concept of states. On the other hand, Ethereum blockchain supports scripting languages and smart contracts; it can maintain state. Ethereum transactions manage state transitions by calling smart contract methods. Ethereum no longer needs to rely on UTOX to manage payments. Instead, it operates using accounts and balances via state transitions. State denotes the current balance of all accounts, along with other data. State is not stored on the blockchain. It is saved off-chain in a Merkle Patricia tree. This is because state is mutable data, while a block is not mutable. As with Bitcoin, a cryptocurrency wallet can be used to manage public and private keys or accounts, which are for receiving or sending ETH. In other words, Ethereum introduced the concept of accounts.

Ethereum supports two types of account: externally owned accounts (controlled by human users via ownership of private keys) and contract accounts.

  • An externally controlled account:
    • Has an Ether balance
    • Can initiate transactions for either transferring Ether or triggering smart contract code
    • Is controlled by users via private keys
    • Has no associated smart contract code
  • A contract account:
    • Has an Ether balance
    • Has associated smart contract code
    • Smart contract code execution is triggered by transactions or calls received from other contracts
  • For both types of account, there are four components:
    • nonce: For an externally owned account, it refers to the number of transactions sent from the account's address; for a contract account, nonce is increased every time this contracts calls another contract
    • balance: It is the number of Wei owned by this address
    • storageRoot: A 256-bit hash of the storage contents of the account
    • codeHash: The hash of the code of this account is EVM; this is the code that gets executed when the address receives a call

When Ether is transferred from contract accounts to an externally owned account, there is a fee, for instance 21,000 gas. When Ether is sent from an externally owned account to a contract account, the fee is higher, and depends on the smart contract code and data being sent in the transaction.

Ethereum addresses have the following format:

  1. Start with the prefix 0x, a common identifier for hexadecimal
  2. Rightmost 20 bytes of the Keccak-256 hash (big-endian) of the ECDSA public key

Since, in hexadecimal, two digits are stored in one byte, a 20-byte address is represented with 40 hexadecimal digits. A sample address is 0xe99356bde974bbe08721d77712168fa074279267.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset