Account state and binary layouts
Account state is the typed view of the bytes stored in an on-chain account. This area defines the account data boundary and turns selected runtime, consensus, validator, and address-table state into values that higher-level APIs can use. It complements Accounts and identity and uses the public-key model described in Keys and signatures.
Account data model
An account couples its owner and balance with optional data bytes. The account bytes remain program-owned data until a parser confirms that they have the expected shape and state version. A successful parse then exposes domain fields such as a durable nonce, vote history, validator metadata, or lookup-table addresses.
The data path separates transport from interpretation:
| Data form | Purpose |
|---|---|
| Byte sequence | Preserve the program-owned account data. |
| Binary codec | Read fixed-width values, lists, optional values, and strings from the byte sequence. |
| Typed account value | Present a known account format as domain fields after validation. |
This diagram shows how account bytes become a typed value only after format checks.
flowchart LR
A[Account bytes] --> B[Account-specific codec]
B --> C{Expected state or layout?}
C -->|Yes| D[Typed account state]
C -->|No| E[Decode error or no matching state]
The parsers accept common byte containers and convert encoded public keys into PublicKey values. Large counters remain bigint values where the account format can exceed JavaScript's safe integer range. These choices keep the typed result aligned with the on-chain representation.
Runtime account state
Runtime account state provides values that programs and transaction builders use to work with cluster state. The account identity is stable even when the state format belongs to the runtime rather than to this client library.
Nonce account state
A nonce account stores a durable nonce that lets a transaction use a stored blockhash instead of a recent blockhash. NonceAccount reads the system account format and exposes its authority, nonce, and legacy fee field for callers that need to inspect or build durable-nonce flows. The parser accepts only initialized nonce accounts and rejects a fee value that cannot be represented safely as a JavaScript number.
The durable nonce is represented as a Blockhash string value. Its authority is a PublicKey, so nonce ownership and transaction signing use the same key model as the rest of the client. The fee calculator remains available for compatibility even though its field is deprecated.
References: packages/…/nonce-account.ts• L12-19 packages/…/nonce-account.ts• L21-31 packages/…/nonce-account.ts• L58-77
Sysvar account identities
Sysvars are special runtime accounts that expose cluster state to programs and transactions. This module gives each supported sysvar a stable public key so account lists can refer to clock, rent, epoch, instruction, blockhash, reward, slot, and stake-history state without rebuilding those identifiers.
These constants identify accounts. They do not decode the state stored in those accounts. Program builders use them when an instruction must pass the matching runtime account, as described in Programs and instructions.
References: packages/…/sysvar.ts• L3-37
Consensus and validator state
Consensus and validator accounts use structured data with versioned layouts. Their parsers translate encoded keys, counters, histories, and optional fields into stable public types while keeping unsupported or invalid account variants out of normal use.
Vote account state
A vote account describes a validator's voting identity and vote history. VoteAccount exposes the node and withdrawer keys, commission, lockouts, root slot, authorized voters, prior voters, epoch credits, and the last vote timestamp. Newer account versions also expose reward collectors, commission rates, pending delegator rewards, and an optional compressed BLS key.
The parser reads the state version before selecting a layout. It supports the older initialized layout, version 3, and version 4. It normalizes version-specific representations into one public shape: landed votes become lockouts, prior voters are returned in logical order, and version 4 basis-point commission data is mapped to the legacy percentage field. Old and unknown versions fail instead of being treated as a different vote state.
References: packages/…/vote-account.ts• L23-37 packages/…/vote-account.ts• L39-115 packages/…/vote-account.ts• L344-460 packages/…/vote-account.ts• L483-551
Validator information state
Validator information is optional metadata attached to a config account. ValidatorInfo recognizes the validator-info config key, requires the companion key to be a signer, and parses the stored string as JSON. The result contains the validator public key and a validated name with optional website, details, icon, and Keybase fields.
The parser returns null when the config account does not have the expected two-key arrangement or key order. It rejects metadata with a missing name or a non-string optional field, which prevents malformed JSON from becoming trusted validator information.
References: packages/…/validator-info.ts• L22-47 packages/…/validator-info.ts• L50-93 packages/…/validator-info.ts• L119-147
Address lookup table state
An address lookup table stores many public keys for compact transaction address references. Its typed state combines table lifecycle data with the ordered addresses that a versioned transaction can load. The table account therefore connects account decoding with the message and instruction flow described in Programs and instructions.
The parser checks the account discriminator before returning deactivation and extension data. It represents a missing authority as undefined, converts each stored address to a PublicKey, and reports the table as active only while its deactivation slot has the special maximum value.
References: packages/…/state.ts• L9-15 packages/…/state.ts• L22-34 packages/…/state.ts• L36-51
Change checklist
When these files or sections are changed, remember to consider these:
- Keep nonce account state validation aligned with the system program's layout and with the safe numeric type used by the public API.
- Keep every supported vote state version mapped to the same public
VoteAccountmeaning. A new encoded field must not silently change the meaning of an existing field such ascommissionorvotes. - Keep validator-info key order, signer rules, and JSON field rules aligned with the config account format.
- Keep sysvar public keys synchronized with every instruction builder that passes runtime accounts to a program.
- Update address lookup table lifecycle rules with any change to its discriminator, authority option, or active-state sentinel.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A nonce account is not initialized. | Durable-nonce parsing stops instead of returning usable nonce state. | Parse only initialized system nonce accounts. |
| A nonce fee value exceeds the safe JavaScript integer range. | The parser rejects the account rather than returning a rounded value. | Preserve the wide encoded value until the range check succeeds. |
| Vote data has an unsupported or old state version. | Vote account parsing fails. | Select only the supported versioned layouts and add an explicit mapping for new versions. |
| Vote prior-voter metadata has an invalid index. | Vote history cannot be put into logical order. | Validate the index against the fixed prior-voter history size. |
| Validator config keys do not identify a signer in the expected arrangement. | No ValidatorInfo value is returned. | Preserve the config-key identity and signer checks. |
| A lookup-table discriminator is wrong or the table is deactivated. | The account is rejected or is not treated as active. | Validate the discriminator and use the defined deactivation sentinel. |
Key files
| File | Why to read it |
|---|---|
| packages/…/nonce-account.ts | Shows the durable-nonce account contract and its state checks. |
| packages/…/vote-account.ts | Defines the versioned vote layouts and their common typed result. |
| packages/…/validator-info.ts | Shows how validator metadata is identified and validated. |
| packages/…/sysvar.ts | Names the runtime accounts used by program instruction flows. |
| packages/…/state.ts | Defines lookup-table lifecycle state and ordered address decoding. |
| packages/…/codecs.ts | Defines the length-prefixed string form used by validator metadata. |