SelfFetchFunctions

type SelfFetchFunctions<TFrom, TTo> = object;

Methods that allow a codec to fetch and decode accounts directly.

These methods are added to codec objects via addSelfFetchFunctions, enabling a fluent API where you can call .fetch() directly on a codec to retrieve and decode accounts in one step.

Examples

Fetching a single account and asserting it exists.

const account = await myAccountCodec.fetch(address);
// account.data is of type TTo.

Fetching a single account that may not exist.

const maybeAccount = await myAccountCodec.fetchMaybe(address);
if (maybeAccount.exists) {
    // maybeAccount.data is of type TTo.
}

Fetching multiple accounts at once.

const accounts = await myAccountCodec.fetchAll([addressA, addressB]);
// All accounts exist.

See

addSelfFetchFunctions

Type Parameters

Type ParameterDescription
TFrom extends objectThe type that the codec encodes from.
TTo extends TFromThe type that the codec decodes to.

Properties

fetch()

readonly fetch: <TAddress>(address, config?) => Promise<Account<TTo, TAddress>>;

Fetches and decodes a single account, throwing if it does not exist.

Type Parameters

Type Parameter
TAddress extends string

Parameters

ParameterType
addressAddress<TAddress>
config?FetchAccountConfig

Returns

Promise<Account<TTo, TAddress>>


fetchAll()

readonly fetchAll: (addresses, config?) => Promise<Account<TTo>[]>;

Fetches and decodes multiple accounts, throwing if any do not exist.

Parameters

ParameterType
addressesAddress[]
config?FetchAccountsConfig

Returns

Promise<Account<TTo>[]>


fetchAllMaybe()

readonly fetchAllMaybe: (addresses, config?) => Promise<MaybeAccount<TTo>[]>;

Fetches and decodes multiple accounts, returning MaybeAccount for each.

Parameters

ParameterType
addressesAddress[]
config?FetchAccountsConfig

Returns

Promise<MaybeAccount<TTo>[]>


fetchMaybe()

readonly fetchMaybe: <TAddress>(address, config?) => Promise<MaybeAccount<TTo, TAddress>>;

Fetches and decodes a single account, returning a MaybeAccount.

Type Parameters

Type Parameter
TAddress extends string

Parameters

ParameterType
addressAddress<TAddress>
config?FetchAccountConfig

Returns

Promise<MaybeAccount<TTo, TAddress>>

On this page