0

After an ICO, a token contract has essentially converted ethers into a token through the minting process.

Once this token’s initial supply has been minted, how do you call the blockchain to return the market cap of that token?

2 Answers 2

2

Market cap = price of currency * circulating supply

So, as an example, the market capitalization at the time of writing of Tezos is 1,550,977,120 euros:

€2.19 (unit price of an XTZ token) * 708,208,731 XTZ (number of Tezos in circulation)

1st : Get Circulating Supply in web3 from a LPtokens(PairAddress)

Step1 : Import Factory Function :

const factoryContract = new ethers.Contract(
  "AddFactoryHere", //Add here
  [
  'event PairCreated(address indexed token0, address indexed token1,address pair, uint)',
  'function getPair(address tokenA, address tokenB) external view returns (address pair)',
  'function balanceOf(address owner) external view returns (uint)',
  'function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast)'
  ],
  signer // Add your here
);

Step2 : What Pair ? Example :

const TokenA = 'AddressHere' 
const TokenB = 'AddressHere' 

Step3 : Call function GetPair to get answer of PairAddress :

const pairAddress = await factoryContract.getPair(TokenA,TokenB);

Step4 : Call function getReserves to get reserves tokens:

Be carreful sometime result of reserve inverse token !!! You need fix it

const pairContract = new ethers.Contract(pairAddress, abi, provider); //Import ABI , build provider etc ...
const reserves = await pairContract.getReserves();

Here you get 2 answer : reserves1 and reserves[0];

And you need get DECIMAL of each token to make good convertion

const tokenContracttoken = new web3.eth.Contract(abiOfToken,"AddressOfToken"); //import AbiOfStandardToken
const decimalstoken = await tokenContracttoken.methods.decimals().call();

Here you have number of Token from a PairAddress .

What to do for get price is just call function getAmountsOut from router with value of 1 to get the current Price of Token do same step as up .. Full method to do is here : Clic here

Note : If you think its hard to do your wrong, its pretty simple its like ask question to someone and get answer like : Hello how are you ? I'm good Its the same for web3.js you call answer like What is Reserve of (WBNB-BUSD) with function provided of smart contract getReserves and you get answer MarketCap is different for eachDex and LiquidityPool if i'm allright

Is that good for you ?

4
  • Could you give code examples?
    – immaxkent
    Feb 28, 2023 at 23:36
  • Add question anything you want we are here to help you
    – forexmp45
    Mar 1, 2023 at 16:48
  • I upvoted the answer, but feel that a warning must be added: do not rely on a pool's spot price for important calculations. It's easy to manipulate. Use oracle prices instead.
    – kfx
    Mar 1, 2023 at 16:53
  • Thanks for the edit👏
    – immaxkent
    Mar 1, 2023 at 22:20
0

What do you exactly mean by "market cap"?

From Coinbase Learn:

For a cryptocurrency like Bitcoin, market capitalization (or market cap) is the total value of all the coins that have been mined. It’s calculated by multiplying the number of coins in circulation by the current market price of a single coin.

So, market cap is the value (usually in dollars) of all your tokens.

If you want to know how many tokens have been minted, you must call the function totalSupply from your token Smart Contract.

1
  • I know what the market cap is. My question is how do you find the market cap of a token , perhaps using an API or something
    – immaxkent
    Feb 23, 2023 at 22:33

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.