Ethereum account

胡家維 Hu Kenneth
Coinmonks
5 min readMay 7, 2018

--

This post is a reference to “How does Ethereum work, anyway?” which written by “ Preethi Kasireddy” and can be found here.

  • Externally Owned Accounts (User accounts is controlled by private keys)
  • Contracts Accounts (controlled by code)

Discover and review best Blockchain softwares

Account state

The account state consists of four components, which are present regardless of the type of account:

  • nonce: If the account is an externally owned account, this number represents the number of transactions sent from the account’s address. If the account is a contract account, the nonce is the number of contracts created by the account.
  • balance: The number of Wei owned by this address. There are 1e+18 Wei per Ether.
  • storageRoot: A 256-bit hash of the root node of a Merkle Patricia tree that encodes the storage contents of the account (a mapping between 256-bit integer values), encoded into the trie as a mapping from the Keccak 256-bit hash of the 256-bit integer keys to the RLP-encoded 256-bit integer values. This tree encodes the hash of the storage contents of this account, and is empty by default.
  • codeHash: The hash of the EVM (Ethereum Virtual Machine) code of this account — this is the code that gets executed should this address receive a message call; it is immutable and thus, unlike all other fields, cannot be changed after construction. All such code fragments are contained in the state database under their corresponding hashes for later retrieval. For contract accounts, this is the code that gets hashed and stored as the codeHash. For externally owned accounts, the codeHash field is the hash of the empty string.

refer to the ethereum yellowpaper for more detail

Externally owned accounts (EOAs)

An externally controlled account

  • has an ether balance,
  • can send transactions (ether transfer or trigger contract code),
  • is controlled by private keys,
  • has no associated code.

Contract accounts (some articles call Contract Wallet)

A contract

  • has an ether balance,
  • has associated code,
  • code execution is triggered by transactions or messages (calls) received from other contracts.
  • when executed — perform operations of arbitrary complexity (Turing completeness) — manipulate its own persistent storage, i.e., can have its own permanent state — can call other contracts

Contract accounts in Exchange Send Ether (ETH) to a user account has a fee of 21000 gas but sending ETH to a contract has a higher fee, which depends on the contract code and data being sent in the transaction.

Advantages of contract accounts over User Account:

  • Contract account can list incoming transactions
  • Contract account can be setup as Multisig Accounts
  • A Multisig Account can be structured such that it has a daily limit which you specify, and only if the daily limit is exceeded will multiple signatures be required

Disadvantages of contract accounts over User Accounts:

  • Contract accounts incur a cost whenever you use them.

Creating user accounts does not cost any gas but creating contract accounts does. You pay to create and use Contract accounts because they use the valuable computational and storage resource of the network.

Another point is that an externally owned account can send message to other externally owned accounts OR to other contract accounts by creating and signing a transaction using its private key. A message between two externally owned accounts is simply a value transfer. But a message from an externally owned account to a contract account activates the contract account’s code, allowing it to perform various actions (e.g. transfer tokens, write to internal storage, mint new tokens, perform some calculation, create new contracts, etc.).

Unlike externally owned accounts, contract accounts can’t initiate new transactions on their own. Instead, contract accounts can only fire transactions in response to other transactions they have received (from an externally owned account or from another contract account). We’ll learn more about contract-to-contract calls in the “Transactions and Messages” section.

Tools :

Types of contract account

There are two type of contract account — Simple account & Multisig( Multisignature) account

Simple account & Multisig account are created and owned by Accounts.

  • Simplet account : Only one account bother creates and owns the account.
  • Multisig account : A Multisig Wallet has several owner Accounts one of which will also be the creator Account.

To create a simple wallet :

  1. Click on ADD WALLET CONTRACT.
  2. Under WALLET CONTRACT TYPE ensure that SINGLE OWNER ACCOUNT is selected, then enter a name for your wallet.
  3. Click on CREATE. Then enter the password of the current account you used in

To create a Multisig wallet :

  1. Click on ADD WALLET CONTRACT.
  2. Under WALLET CONTRACT TYPE select MULTISIGNATURE WALLET CONTRACT.
  3. Set up how many owner owns this wallet. The default is 3 owners. In my case, I change it to 2.
  4. Fill in owners’ address which depends on your settings.
  5. Click on CREATE. Then enter the password of the current account you used.
  6. Copy and paste the addresses of the other two owner Accounts.
    IMPORTANT: Do not add a Contract Wallet as the owner of a Multisig Wallet. Only Accounts can be owners.

The default settings for Multisig accounts is displayed. In this example, we are going with the default 2-of-3 setting, but we have reduced the daily limit to 10 ether.

Multisig account user case

Click to read more about ethereum

--

--

胡家維 Hu Kenneth
Coinmonks

撰寫任何事情,O型水瓶混魔羯,咖啡愛好者,Full stack/blockchain Web3 developer,Founder of Blockchain&Dapps meetup ,Udemy teacher。 My Linktree: https://linktr.ee/kennethhutw