• 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

    • TData extends object

      The type of this account's data.

    • TAddress extends string = string

      Supply a string literal to define an account having a particular address.

    Parameters

    Returns asserts account is Account<TData, TAddress>

    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>;
  • Type Parameters

    • TData extends object
    • TAddress extends string = string

    Parameters

    • account: MaybeAccount<Uint8Array<ArrayBufferLike> | TData, TAddress>

    Returns asserts account is MaybeAccount<TData, TAddress>