2

All. I’m trying to find a free api end point which will return the total supply of tokens similar to how solscan displays the total supply.

Appreciate the help in advance.

2 Answers 2

2

The above answer is correct, but here's another way you can fetch total token supply with @solana/web3.js:

// "tokenMint" is of type PublicKey
const tokenSupplyInfo = await connection.getTokenSupply(tokenMint);

// Total supply
const supply = tokenSupplyInfo.value.amount;

// Total supply adjusted for decimals
const uiSupply = tokenSupplyInfo.value.uiAmount
2

You can make use of the DAS API,

using TypeScript and the UMI library,

import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { fetchDigitalAsset } from '@metaplex-foundation/mpl-token-metadata'
import { dasApi } from "@metaplex-foundation/digital-asset-standard-api";

const umi = createUmi(clusterApiUrl("devnet"));
umi.use(keypairIdentity(keypair)).use(dasApi());

const token =  publickey("HabTivxE5cnR1G9CmXf3kysdKSmzJncedPstiqiUZBMv");
const fetchAsset = async () => {
    const asset = await umi.rpc.getAsset(publicKey(token));
    console.log("asset \n", asset);
}

You can find details in the token_info field

{

// .... skipped 
  supply: null,
  mutable: true,
  burnt: false,
  token_info: {
    supply: 83600000000000,
    decimals: 6,
    token_program: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
    mint_authority: '4c9a1WRCxDacZAUJJnHwNvVJzeE6Tgyz8qB9Lww8ikhZ',
    freeze_authority: '4c9a1WRCxDacZAUJJnHwNvVJzeE6Tgyz8qB9Lww8ikhZ'
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.