Ask or search…
K
Links

Get Token Accounts

Get information about all token accounts for a specific mint or a specific owner.

Overview

A token account is an account that holds information about a specific token that is held by an address. For example, an address that holds some BONK (an SPL token) will have a token account for BONK. This token account contains information about the mint address, owner address, and the amount of the specific token in the account. Mint: DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263(BONK) Owner: 8uDncGPHZJtFnyCktVSbdWmgt7xAiHgwq8ZmxKaK5ZJ1(Owners wallet address) Token Account: 8tM8XNyQEn999zQ2tCJeGRs7PJKcJPN1nh3TYvJ6ioCs
The getTokenAccounts API will return all the token accounts associated with a specific mint or owner account. This is an efficient way to get all the owners of a specific SPL token or get all the token accounts that an address owns.

Parameters

You can specify an address and receive a list of all the token accounts it owns. You are also able to specify a specific mint address and get all the token accounts associated with that token. On top of this, you are able to use these two parameters in conjunction and get the token account associated with a specific mint and a specific owner.
You can also include a showZeroBalance flag in the display options to include empty token accounts. Empty token accounts are accounts that once held a token but no longer do.

Response

The API response will include the following details:
  • address: The address of the token account.
  • mint: The mint address of the token.
  • owner: The owner of the token account’s address.
  • amount: The quantity of the token that is currently held in the respective token account.
  • delegated_amount: The quantity of the token that has been delegated to another account.
  • frozen: Indicates if a token account is frozen or not.

Suggested use cases

  • Getting all the holders of a specific token.
  • Token-gated experiences (with SPL tokens)
  • Finding the biggest holders of a specific token.

Examples

How to get all the token accounts for a specific owner:

const url = `https://mainnet.helius-rpc.com/?api-key=<API-KEY>`;
const getTokenAccounts = async () => {
const fetch = (await import("node-fetch")).default;
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
method: "getTokenAccounts",
id: "helius-test",
params: {
page: 1,
limit: 100,
"displayOptions": {
"showZeroBalance": false,
},
owner: "CckxW6C1CjsxYcXSiDbk7NYfPLhfqAm3kSB5LEZunnSE",
},
}),
});
const data = await response.json();
if (!data.result) {
console.error("No result in the response", data);
return;
}
console.log(JSON.stringify(data.result, null, 2));
};
getTokenAccounts();
Response:
{
"total": 2,
"limit": 100,
"page": 1,
"token_accounts": [
{
"address": "CVMR1nbxTcQ7Jpa1p137t5TyKFii3Y7Vazt9fFct3tk9",
"mint": "SHDWyBxihqiCj6YekG2GUr7wqKLeLAMK1gHZck9pL6y",
"owner": "CckxW6C1CjsxYcXSiDbk7NYfPLhfqAm3kSB5LEZunnSE",
"amount": 100000000,
"delegated_amount": 0,
"frozen": false
},
{
"address": "8U1RBVQsynGgtikLpDaRKZSEvWAx1BB9otCoFbE8rV59",
"mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"owner": "CckxW6C1CjsxYcXSiDbk7NYfPLhfqAm3kSB5LEZunnSE",
"amount": 19990000,
"delegated_amount": 0,
"frozen": false
}
]
}

How to get all the holders of an SPL token:

This example makes use of page-based pagination and gets all the holders of $BONK. In this example only unique owner addresses are saved to a file.
const url = `https://mainnet.helius-rpc.com/?api-key=<API-KEY>`;
const fs = require("fs");
const getTokenAccounts = async () => {
const fetch = (await import("node-fetch")).default;
let page = 1;
let allOwners = new Set();
while (true) {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
method: "getTokenAccounts",
id: "helius-test",
params: {
page: page,
limit: 1000,
displayOptions: {},
mint: "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263",
},
}),
});
const data = await response.json();
if (!data.result || data.result.token_accounts.length === 0) {
console.log(`No more results. Total pages: ${page - 1}`);
break;
}
console.log(`Processing results from page ${page}`);
data.result.token_accounts.forEach((account) =>
allOwners.add(account.owner)
);
page++;
}
fs.writeFileSync(
"output.json",
JSON.stringify(Array.from(allOwners), null, 2)
);
};
getTokenAccounts();
Response
[
"111An9SVxuPpgjnuXW9Ub7hcVmZpYNrYZF4edsGwJEW",
"11Mmng3DoMsq2Roq8LBcqdz6d4kw9oSD8oka9Pwfbj",
"112uNfcC8iwX9P2TkRdJKyPatg6a4GNcr9NC5mTc2z3",
"113uswn5HNgEfBUKfK4gVBmd2GpZYbxd1N6h1uUWReg",
"11CyvpdYTqFmCVWbJJeKFNX8F8RSjNSYW5VVUi8eX4P",
"11MANeaiHEy9S9pRQNu3nqKa2gpajzX2wrRJqWrf8dQ",
"11MDcdk32JB8bJzpcCrGijaUbJEUpAgpikVfLrpgru1",
"11MiBon8Vi6gfvwBz1tCFno52W4QZj4qgktLy5ZNQTz",
"11MwoPvG25NZQcZaGBkmphb4B5bvPjKBE4zXNaZtZau",
"11TaqNq9a7PBkYbGLfzpgC5VAr6XRtGBGC5T2AvUVus",
...
"FEwuzsatWmqzxa6AtEWoMsKo2K7vRdHaG8UsuuAzooGn",
"FEwxV2LT13ifNMs1KdpE87AzBNpK6SGDsACdvqs5utYb"
]