Skip to content

Account

The state of an account as eth_getAccount returns it: the four fields an account has in the state trie.

import { Effect } from "effect";
import { Address } from "@ethect/core";
import { Eth } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
const state = Effect.gen(function* () {
const account = yield* Eth.getAccount(ADDRESS, "latest");
if (account === null) return null;
// account: Account.Account
return { nonce: account.nonce, balance: account.balance };
});
Schema Type Describes Returned by
Account.schema Account.Account the state of one account Eth.getAccount
Field Type Notes
nonce number the number of transactions the account has sent
balance bigint in wei
storageRoot Hash the root of the account’s storage trie
codeHash Hash the hash of the account’s code
  • Hashes, not contents. The account holds the hash of its code and the root of its storage. Read the code with Eth.getCode and a slot with Eth.getStorageAt.
  • An account without code or storage has two fixed hashes. codeHash is the hash of no bytes, and storageRoot is the root of an empty trie.
  • Not a signer. An Account is the state of an address on the chain. It holds no key and signs nothing.
  • Numbers. nonce is a number and balance a bigint. See values on the wire.

Compare codeHash with the hash of no bytes to tell a contract from a plain account.

import { Hash } from "@ethect/core";
import { type Account } from "@ethect/core/rpc";
const emptyCodeHash = Hash.keccak256(new Uint8Array());
// "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
const hasCode = (account: Account.Account): boolean =>
account.codeHash !== emptyCodeHash;