Skip to content

Instantly share code, notes, and snippets.

@KoenRijpstra
Created March 13, 2024 09:54
Show Gist options
  • Save KoenRijpstra/3445e5c52cc4764ab6910d1277a81777 to your computer and use it in GitHub Desktop.
Save KoenRijpstra/3445e5c52cc4764ab6910d1277a81777 to your computer and use it in GitHub Desktop.
Helius Get Token Info
const API_KEY = "YOUR_API_KEY";
const getTokenInfo = async (token) => {
const getAssetResponse = await fetch(`https://mainnet.helius-rpc.com/?api-key=${API_KEY}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: "my-id",
method: "getAsset",
params: {
id: token,
displayOptions: {
showFungible: true
},
},
}),
});
const getAssetData = await getAssetResponse.json();
const getAssetResult = getAssetData.result;
const tokenMetaDataResponse = await fetch(
`https://api.helius.xyz/v0/token-metadata?api-key=${API_KEY}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
mintAccounts: [token]
}),
}
);
const tokenMetaDataData = await tokenMetaDataResponse.json();
const tokenMetaDataResult = tokenMetaDataData[0];
console.log("Address", getAssetResult.id);
console.log("Name", getAssetResult.content.metadata.name);
console.log("Symbol", getAssetResult.content.metadata.symbol);
console.log("Supply", getAssetResult.token_info.supply);
console.log("Decimals", getAssetResult.token_info.decimals);
console.log("Price info", getAssetResult.token_info.price_info);
console.log("Mutable", getAssetResult.mutable);
console.log("Mintable", tokenMetaDataResult.onChainAccountInfo.accountInfo.data.parsed.info.mintAuthority!=="");
console.log("Freezable", tokenMetaDataResult.onChainAccountInfo.accountInfo.data.parsed.info.freezeAuthority!=="");
console.log("Creators", getAssetResult.creators);
console.log("Update Authority (UA)", getAssetResult.authorities[0].address);
};
getTokenInfo("J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment