@lelantos-org/sdk / index / Wallet
Class: Wallet โ
Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:22
The high-level wallet surface. Wallet in ./wallet.ts is the shipped implementation; depend on this interface to keep tests mockable.
Amounts are always in circuit units โ tokenBaseUnits = amount * asset.scale. Use wallet.asset(id) plus parseAmount / formatAmount from ./assets.js to move between circuit units and what a user types.
Typical lifecycle:
const wallet = await connect({ network: "anvil", privateKey, rpcUrl });
await wallet.sync(); // notes + Merkle tree
const weth = requireTokenMeta(await wallet.asset(assetId(1n)));
await wallet.deposit({ asset: weth.id, amount: parseAmount("0.25", weth) });
await wallet.sync();
wallet.balance(weth.id);Implements โ
WalletApiSpendContextSyncContext
Properties โ
address โ
readonly address: ShieldedAddress;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:26
This wallet's shielded lelantos1โฆ address (bech32m).
Implementation of โ
cfg โ
readonly cfg: ResolvedWalletConfig;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:27
Implementation of โ
SpendContext.cfgJ โ
readonly J: WasmJubjub;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:24
Implementation of โ
SpendContext.Jkeys โ
readonly keys: SpendingKey;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:25
Implementation of โ
P โ
readonly P: Poseidon;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:23
Implementation of โ
SpendContext.PAccessors โ
chain โ
Get Signature โ
get chain(): ChainAdapter;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:53
Cast to a concrete adapter type for adapter-specific accessors.
Returns โ
Cast to a concrete adapter type for adapter-specific accessors.
Implementation of โ
noteSource โ
Get Signature โ
get noteSource(): NoteSource;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:46
Returns โ
Implementation of โ
noteStore โ
Get Signature โ
get noteStore(): NoteStore;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:45
Returns โ
Implementation of โ
nullifierStore โ
Get Signature โ
get nullifierStore(): NullifierStore;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:48
Returns โ
Implementation of โ
SyncContext.nullifierStoreprover โ
Get Signature โ
get prover(): Prover;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:50
Returns โ
Implementation of โ
scanner โ
Get Signature โ
get scanner(): Scanner;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:52
Returns โ
Implementation of โ
selector โ
Get Signature โ
get selector(): CoinSelector;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:51
Returns โ
Implementation of โ
submitter โ
Get Signature โ
get submitter(): Submitter;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:49
Returns โ
Implementation of โ
treeStore โ
Get Signature โ
get treeStore(): TreeStore;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:47
Returns โ
Implementation of โ
SpendContext.treeStoreMethods โ
asset() โ
asset(ref, opts?): Promise<AssetInfo>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:138
Registry entry for id plus ERC-20 symbol/decimals when the adapter exposes them. Cached for the wallet's lifetime โ asset entries are immutable apart from the disabled flag; { refresh: true } re-reads it.
Parameters โ
| Parameter | Type |
|---|---|
ref | AssetRef |
opts? | { refresh?: boolean; } |
opts.refresh? | boolean |
Returns โ
Promise<AssetInfo>
Implementation of โ
assets() โ
assets(): Promise<AssetInfo[]>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:142
Every asset this chain has registered, lowest id first.
Returns โ
Promise<AssetInfo[]>
Implementation of โ
awaitCommitments() โ
awaitCommitments(cms, opts?): Promise<AwaitCommitmentsResult>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:127
Poll sync() until every commitment in cms is stored locally.
Reports whether they arrived โ see AwaitCommitmentsResult. Does not throw on timeout by default: this runs after a successful broadcast, so a lagging indexer is not a failed transaction.
Parameters โ
| Parameter | Type |
|---|---|
cms | string[] |
opts? | AwaitCommitmentsOpts |
Returns โ
Promise<AwaitCommitmentsResult>
Implementation of โ
balance() โ
balance(asset): CircuitAmount;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:130
Unspent total for one asset, in circuit units.
Parameters โ
| Parameter | Type |
|---|---|
asset | AssetIdLike |
Returns โ
Implementation of โ
balances() โ
balances(): Map<AssetId, CircuitAmount>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:131
Unspent totals keyed by asset id โ one pass for a multi-asset view.
Returns โ
Map<AssetId, CircuitAmount>
Implementation of โ
cancelDeposit() โ
cancelDeposit(id, inputs): Promise<{
txHash: Hex32;
}>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:164
Cancel an escrowed deposit. Permissionless after cancelDelay blocks. Caller supplies the DepositEscrowed event payload for the on-chain digest check.
Parameters โ
| Parameter | Type |
|---|---|
id | bigint |
inputs | CancelDepositInputs |
Returns โ
Promise<{ txHash: Hex32; }>
Implementation of โ
compact() โ
compact(): Promise<{
removed: number;
}>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:117
Drop notes flagged spent: true from the underlying store. Returns the number of notes pruned. Balance is unaffected; this only shrinks the on-disk file. Live notes and reconcile state are preserved.
Returns โ
Promise<{ removed: number; }>
Implementation of โ
create() โ
static create(source, cfg): Promise<Wallet>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:65
Build from any key source. Wires defaults for omitted pluggables. Collects every config problem into WalletConfigError.missing.
Parameters โ
| Parameter | Type |
|---|---|
source | KeySource |
cfg | WalletConfig |
Returns โ
Promise<Wallet>
deposit() โ
deposit(args): Promise<DepositResult>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:158
Shield ERC-20 into the MASP via Permit2 escrow. Funds sit in escrow until the relayer flushes a batch (or cancelDeposit after cancelDelay blocks). For native ETH set asEth: true.
Parameters โ
| Parameter | Type |
|---|---|
args | DepositOptions |
Returns โ
Promise<DepositResult>
Implementation of โ
dispose() โ
dispose(): Promise<void>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:208
Release everything this wallet holds: scanner workers and, if one was built, the prover's.
WorkerPoolScanner spawns 2โ8 workers per wallet, each with its own wasm heap, and Scanner.dispose existed with no caller โ so an app that rebuilds its wallet on an account or network switch leaked a whole pool every time.
Idempotent, and safe on a wallet that never synced or proved. The wallet must not be used afterwards.
Returns โ
Promise<void>
Implementation of โ
feeBps() โ
feeBps(): Promise<bigint>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:57
SpendContext โ config override, else the chain's fee.
Returns โ
Promise<bigint>
Implementation of โ
SpendContext.feeBpsmarkPendingSpend() โ
markPendingSpend(noteIds): Promise<void>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:195
Reserve notes against a spend whose outcome is unknown, so the selector stops offering them until reconciliation or expiry settles it.
Called automatically when a submit fails without an answer; see submitSpend and StoredNote.pendingSpendAt.
Parameters โ
| Parameter | Type |
|---|---|
noteIds | string[] |
Returns โ
Promise<void>
Implementation of โ
SpendContext.markPendingSpendmarkSpent() โ
markSpent(noteIds): Promise<void>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:187
Called automatically by transfer / withdraw; exposed for alternative spend flows.
Parameters โ
| Parameter | Type |
|---|---|
noteIds | string[] |
Returns โ
Promise<void>
Implementation of โ
notes() โ
notes(filter?): WalletNote[];Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:129
Omit a field to stop filtering on it; notes() returns everything.
Parameters โ
| Parameter | Type |
|---|---|
filter? | NotesFilter |
Returns โ
Implementation of โ
quoteFee() โ
quoteFee(args): Promise<FeeQuoteResult>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:150
What relaying kind costs and what it may be paid in, before building anything.
options[].affordable is checked against this wallet's own balances, so a UI can offer only the assets the holder can actually pay with.
Parameters โ
| Parameter | Type |
|---|---|
args | QuoteFeeArgs |
Returns โ
Promise<FeeQuoteResult>
Implementation of โ
refresh() โ
refresh(): Promise<void>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:116
Reload in-memory cache from NoteStore after external mutation.
Returns โ
Promise<void>
Implementation of โ
resolveAsset() โ
resolveAsset(ref): Promise<AssetInfo>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:59
SpendContext โ id, token address or symbol to a registry entry.
Parameters โ
| Parameter | Type |
|---|---|
ref | AssetRef |
Returns โ
Promise<AssetInfo>
Implementation of โ
SpendContext.resolveAssetselectNotes() โ
selectNotes(
asset,
target,
opts?
): SelectionResult;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:152
Parameters โ
| Parameter | Type |
|---|---|
asset | AssetId |
target | CircuitAmount |
opts? | SelectOpts |
Returns โ
Implementation of โ
spendableMax() โ
spendableMax(asset, opts?): Promise<SpendableMax>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:128
The largest amount of asset a single spend can cover, and what is holding the rest back.
Not the balance. The selector withholds notes that are reserved by an unconfirmed spend, still in their spend cooldown, or below the dust threshold, and a spend can consume only maxInputs of what remains โ so a "max" built on the balance produces InsufficientCoverError against a figure the caller itself supplied. withheld breaks the difference down by cause so a UI can say which it is.
Takes the same SelectOpts a spend does, so the prediction and the spend cannot be computed under different rules. maxInputs defaults to the circuit's nIn; pass nIn - 1 when a cross-asset fee will need an input slot of its own, and fee for one paid in this same asset.
Parameters โ
| Parameter | Type |
|---|---|
asset | AssetId |
opts? | SelectOpts |
Returns โ
Promise<SpendableMax>
Implementation of โ
storedNotes() โ
storedNotes(): readonly StoredNote[];Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:55
SpendContext โ the raw stored-note list.
Returns โ
readonly StoredNote[]
Implementation of โ
SpendContext.storedNotesswap() โ
swap(args): Promise<SwapResult>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:182
Atomic shielded swap. Leg-1 transact_2x2 unshields to SwapWrapper; leg-2 deposit request re-shields the B note. Bundled via submitter.submitSwap. args.amount is gross publicOut in circuit units of assetIn; MASP skims feeBps before transferring.
Parameters โ
| Parameter | Type |
|---|---|
args | SwapOptions |
Returns โ
Promise<SwapResult>
Implementation of โ
sync() โ
sync(opts?): Promise<SyncResult>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:108
Pull encrypted notes, the Merkle tree, and the spent set in parallel, then reconcile which local notes are now spent. Convenience wrapper around syncNotes + syncTree + syncNullifiers.
Parameters โ
| Parameter | Type |
|---|---|
opts? | SyncOpts |
Returns โ
Promise<SyncResult>
Implementation of โ
syncNotes() โ
syncNotes(opts?): Promise<SyncResult>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:90
Pull encrypted notes, trial-decrypt with ivk + dk, persist hits.
Pages the feed to exhaustion, resuming from the cursor on NotesFile.cursor, so a caught-up wallet fetches nothing. Idempotent: re-scanning a note already stored is dropped by cm. Does not sync the tree. limit is the page size, not a ceiling on notes fetched.
Parameters โ
| Parameter | Type |
|---|---|
opts? | SyncOpts |
Returns โ
Promise<SyncResult>
Implementation of โ
syncNullifiers() โ
syncNullifiers(): Promise<void>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:102
Fetch new spent-nullifier chunks into the local set. Idempotent โ resumes from its own cursor. reconcileSpentOnChain reads this set, so a stale mirror only ever under-reports spends; it never marks a live note spent.
Returns โ
Promise<void>
syncTree() โ
syncTree(): Promise<void>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:95
Fetch new Merkle commitment chunks and rebuild the local tree. Idempotent โ resumes from syncedCount cursor. Does not scan notes.
Returns โ
Promise<void>
Implementation of โ
transfer() โ
transfer(args): Promise<TransferResult>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:171
Shielded transfer: 1-2 notes โ send-note + change-note โ submit โ mark spent. Throws InsufficientCoverError on no 1/2-note cover.
Parameters โ
| Parameter | Type |
|---|---|
args | TransferOptions |
Returns โ
Promise<TransferResult>
Implementation of โ
withdraw() โ
withdraw(args): Promise<WithdrawResult>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:173
Unshield ERC20 to args.to. Throws InsufficientCoverError on no cover.
Parameters โ
| Parameter | Type |
|---|---|
args | WithdrawOptions |
Returns โ
Promise<WithdrawResult>
Implementation of โ
withdrawEth() โ
withdrawEth(args): Promise<WithdrawResult>;Defined in: @lelantos-org/sdk/dist/wallet/wallet.d.ts:175
Unshield to raw ETH via NativeAdapter.withdrawNative, which unwraps.
Parameters โ
| Parameter | Type |
|---|---|
args | WithdrawEthOptions |
Returns โ
Promise<WithdrawResult>