Kit
Functions

assertAccountDecoded

Call Signature

assertAccountDecoded<TData, TAddress>(account): asserts account is Account<TData, TAddress>

Asserts that an account stores decoded data, ie. not a Uint8Array.

Note that it does not check the shape of the data matches the decoded type, only that it is not a Uint8Array.

Type Parameters

Type ParameterDefault typeDescription
TData extends object-The type of this account's data.
TAddress extends stringstringSupply a string literal to define an account having a particular address.

Parameters

ParameterType
accountAccount<Uint8Array<ArrayBufferLike> | TData, TAddress>

Returns

asserts account is Account<TData, TAddress>

Example

type MyAccountData = { name: string; age: number };
 
const myAccount: Account<MyAccountData | Uint8Array, '1234..5678'>;
assertAccountDecoded(myAccount);
 
// now the account data can be used as MyAccountData
account.data satisfies MyAccountData;

This is particularly useful for narrowing the result of fetching a JSON parsed account.

const account: MaybeAccount<MockData | Uint8Array> = await fetchJsonParsedAccount<MockData>(
    rpc,
    '1234..5678' as Address,
);
 
assertAccountDecoded(account);
// now we have a MaybeAccount<MockData>
account satisfies MaybeAccount<MockData>;

Call Signature

assertAccountDecoded<TData, TAddress>(account): asserts account is MaybeAccount<TData, TAddress>

Asserts that an account stores decoded data, ie. not a Uint8Array.

Note that it does not check the shape of the data matches the decoded type, only that it is not a Uint8Array.

Type Parameters

Type ParameterDefault typeDescription
TData extends object-The type of this account's data.
TAddress extends stringstringSupply a string literal to define an account having a particular address.

Parameters

ParameterType
accountMaybeAccount<Uint8Array<ArrayBufferLike> | TData, TAddress>

Returns

asserts account is MaybeAccount<TData, TAddress>

Example

type MyAccountData = { name: string; age: number };
 
const myAccount: Account<MyAccountData | Uint8Array, '1234..5678'>;
assertAccountDecoded(myAccount);
 
// now the account data can be used as MyAccountData
account.data satisfies MyAccountData;

This is particularly useful for narrowing the result of fetching a JSON parsed account.

const account: MaybeAccount<MockData | Uint8Array> = await fetchJsonParsedAccount<MockData>(
    rpc,
    '1234..5678' as Address,
);
 
assertAccountDecoded(account);
// now we have a MaybeAccount<MockData>
account satisfies MaybeAccount<MockData>;

On this page