fetchTokenAccounts
function fetchTokenAccounts<TMintAddress, TOwner>(
rpc,
mint,
owner,
config): Promise<{
accounts: Account<Token>[];
mint: Account<Mint>;
totalBalance: bigint;
}>;Fetch all the the token accounts for a given mint and owner Address. Automatically fetching
the Mint account itself and calculating the total balance of all the owner's token accounts.
Example
const { mint, accounts, totalBalance } = await fetchTokenAccounts(
rpc,
"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" as Address, // (mint for USDC on mainnet)
"nick6zJc6HpW3kfBm4xS2dmbuVRyb5F3AnUvj5ymzR5" as Address, // owner address
);Type Parameters
| Type Parameter | Default type |
|---|---|
TMintAddress extends string | string |
TOwner extends string | string |
Parameters
| Parameter | Type | Description |
|---|---|---|
rpc | Rpc<GetTokenAccountsByOwnerApi & GetAccountInfoApi> | - |
mint | | Address<TMintAddress> | Account<Mint> | - |
owner | Address<TOwner> | - |
config | { abortSignal?: AbortSignal; commitment?: Commitment; dataSlice?: Readonly<{ length: number; offset: number; }>; minContextSlot?: bigint; } | - |
config.abortSignal? | AbortSignal | - |
config.commitment? | Commitment | Fetch the details of the accounts as of the highest slot that has reached this level of commitment. |
config.dataSlice? | Readonly<{ length: number; offset: number; }> | Define which slice of the accounts' data you want the RPC to return. Use this to save network bandwidth and encoding time when you do not need the entire buffer. Data slicing is only available for "base58", "base64", and "base64+zstd" encodings. |
config.minContextSlot? | bigint | Prevents accessing stale data by enforcing that the RPC node has processed transactions up to this slot |
Returns
Promise<{
accounts: Account<Token>[];
mint: Account<Mint>;
totalBalance: bigint;
}>