Skip to content

WalletRuntime

A wallet following a chain (the devnet, or a network through its indexer): shielded and DUST state kept in step with the chain, with checkpoints so a transaction that does not land can be rolled back and the blocks since replayed. Used by the solvers, the treasury and the demo wallet.

readonly client: ChainClient


readonly networkId: string


readonly params: LedgerParameters


readonly shielded: ShieldedWallet


readonly dust: DustWallet


cursor: number


optional lastBlock?: ChainBlock


optional lastError?: Error

The last sync failure (a chain that does not answer, or a diverged state).

save(): void

Writes the state now (atomically; readable by this user only). Called as blocks are applied and on stop.

void


onBlock(fn): () => void

Parameter Type
fn (b) => void

() => void


sync(waitMs?): Promise<number>

Parameter Type
waitMs? number

Promise<number>


start(intervalMs?): void

Parameter Type
intervalMs? number

void


stop(): void

void


exclusive<T>(fn): Promise<T>

Runs fn with sync paused; fn may build transactions against a stable state.

Type Parameter
T
Parameter Type
fn () => T | Promise<T>

Promise<T>


checkpoint(): Checkpoint

Checkpoint


rollback(cp): Promise<void>

Restores a checkpoint and replays every block since it.

Parameter Type
cp Checkpoint

Promise<void>


waitForHeight(height, timeoutMs?): Promise<void>

Blocks until the chain is past height and this wallet has applied it.

Parameter Type
height number
timeoutMs? number

Promise<void>


chainHeight(): Promise<number>

Promise<number>


isRegistered(u): boolean

Parameter Type
u NightUtxo

boolean


nightUtxos(): Promise<NightUtxo[]>

This wallet's NIGHT, each with whether it generates DUST for it.

Promise<NightUtxo[]>


unshieldedUtxos(token?): Promise<NightUtxo[]>

This wallet's unshielded outputs of token, or of every token (NIGHT among them).

Parameter Type
token? string

Promise<NightUtxo[]>


dustTime(fallback?): Date

The time a DUST spend declares: the last block this wallet applied, in whole seconds (fallback, the wall clock, before any). A node checks the spend against its DUST trees as they were at that time, and this wallet's trees are those after that block; a later time fails (InvalidDustSpendProof) once anyone's DUST changes in between, and on a network the indexer serves only finalized blocks, some behind the node. Times back to the ledger's grace period (3 h on Preprod) are accepted.

Parameter Type
fallback? Date

Date


ensureDust(nightAmount?, opts?): Promise<void>

DUST for fees: NIGHT registered for DUST generation, if the wallet has no DUST. On the devnet the NIGHT comes from the faucet and is claimed; on a network it must already be there (the tNIGHT faucet), and the registration is proven by seal (bytes as the chain takes them).

Only the largest unregistered UTXO is registered. A registration re-outputs its inputs as one UTXO, so registering all of a wallet's would undo a maker's lots; and under ledger 9's costs a registration of two inputs already takes the node longer to check than its size allows (17.9 ms in 644 bytes against Preprod's 15 ms: FeeCalculation, 231). A wallet whose registrations a fork cleared has several, its lots among them.

Parameter Type
nightAmount? bigint
opts? { seal?: (tx) => Promise<Uint8Array<ArrayBufferLike>>; }
opts.seal? (tx) => Promise<Uint8Array<ArrayBufferLike>>

Promise<void>