Kit
Functions

fetchJsonParsedAccount

fetchJsonParsedAccount<TData, TAddress>(rpc, address, config?): Promise<{ address: Address<TAddress>; exists: false; } | BaseAccount & object & object | BaseAccount & object & object>

Fetches a MaybeAccount from the provided RPC client and address by using getAccountInfo under the hood with the jsonParsed encoding.

It may also return a MaybeEncodedAccount if the RPC client does not know how to parse the account at the requested address. In any case, the expected data type should be explicitly provided as the first type parameter.

Type Parameters

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

Parameters

ParameterType
rpcRpc<GetAccountInfoApi>
addressAddress<TAddress>
config?FetchAccountConfig

Returns

Promise<{ address: Address<TAddress>; exists: false; } | BaseAccount & object & object | BaseAccount & object & object>

Example

type TokenData = { mint: Address; owner: Address };
const myAccount = await fetchJsonParsedAccount<TokenData>(rpc, myAddress);
myAccount satisfies MaybeAccount<TokenData> | MaybeEncodedAccount;
 
// With custom configuration.
const myAccount = await fetchJsonParsedAccount<TokenData>(rpc, myAddress, {
    abortSignal: myAbortController.signal,
    commitment: 'confirmed',
});

On this page