Kit
Functions

decodeAccount

Call Signature

decodeAccount<TData, TAddress>(encodedAccount, decoder): Account<TData, TAddress>

Transforms an EncodedAccount into an Account (/api/functions/or a MaybeEncodedAccount into a MaybeAccount) by decoding the account data using the provided Decoder instance.

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
encodedAccountEncodedAccount<TAddress>
decoderDecoder<TData>

Returns

Account<TData, TAddress>

Example

type MyAccountData = { name: string; age: number };
 
const myAccount: EncodedAccount<'1234..5678'>;
const myDecoder: Decoder<MyAccountData> = getStructDecoder([
    ['name', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
    ['age', getU32Decoder()],
]);
 
const myDecodedAccount = decodeAccount(myAccount, myDecoder);
myDecodedAccount satisfies Account<MyAccountData, '1234..5678'>;

Call Signature

decodeAccount<TData, TAddress>(encodedAccount, decoder): MaybeAccount<TData, TAddress>

Transforms an EncodedAccount into an Account (/api/functions/or a MaybeEncodedAccount into a MaybeAccount) by decoding the account data using the provided Decoder instance.

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
encodedAccountMaybeEncodedAccount<TAddress>
decoderDecoder<TData>

Returns

MaybeAccount<TData, TAddress>

Example

type MyAccountData = { name: string; age: number };
 
const myAccount: EncodedAccount<'1234..5678'>;
const myDecoder: Decoder<MyAccountData> = getStructDecoder([
    ['name', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
    ['age', getU32Decoder()],
]);
 
const myDecodedAccount = decodeAccount(myAccount, myDecoder);
myDecodedAccount satisfies Account<MyAccountData, '1234..5678'>;

On this page