Skip to main content

8.5 Account State

In Xiden, there are two types of accounts: External Owned Accounts (EOA) and Contract Accounts. An EOA account is an account that regular users have, that they can use to send Xden to one another and deploy smart contracts with. A contract account is an account that is created when a smart contract is deployed. Every smart contract has its own Xiden account.

The account state contains information about an Xiden account. For example, it stores how much Xden an account has, and the number of transactions sent by the account. Each account has an account state.

Let's take a look into each one of the fields in the account state:

  • nonce - Number of transactions sent from this address (if this is an External Owned Account - EOA) or the number of contract creations made by this account
  • balance - Total Xden (in Wei) owned by this account
  • storageRoot - Hash of the root node of the account storage trie
  • codeHash - For contract accounts, the hash of the EVM code of this account. For EOAs, this will be empty.

One important detail about the account state is that all fields (except the codeHash) are mutable. For example, when one account sends some Xden to another, the nonce will be incremented, and the balance will be updated to reflect the new balance.

One of the consequences of the codeHash being immutable is that if you deploy a contract with a bug, you can't update the same contract. You need to deploy a new contract (the buggy version will be available forever). This is why it is important to use tools like Truffle to develop and test your smart contracts and follow the best practices when working with Solidity. The Account Storage trie is where the data associated with an account is stored. This is only relevant for Contract Accounts, as for EOAs the storageRoot is empty, and the codeHash is the hash of an empty string.

account state