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 };});Schemas
Section titled “Schemas”| Schema | Type | Describes | Returned by |
|---|---|---|---|
Account.schema |
Account.Account |
the state of one account | Eth.getAccount |
Fields
Section titled “Fields”| 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 |
Behavior
Section titled “Behavior”- Hashes, not contents. The account holds the hash of its code and the root of its storage.
Read the code with
Eth.getCodeand a slot withEth.getStorageAt. - An account without code or storage has two fixed hashes.
codeHashis the hash of no bytes, andstorageRootis the root of an empty trie. - Not a signer. An
Accountis the state of an address on the chain. It holds no key and signs nothing. - Numbers.
nonceis anumberandbalanceabigint. See values on the wire.
An account without code
Section titled “An account without code”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;