I want to get a market cap of some specific coin (BTC, ETH, DOT, BNB etc) from an Ethereum smart contract written in Solidity.

Market cap is obviously = price * current supply

I can use an oracle like ChainLink to get

  • a price of any coin (e.g. BTC / USD)
  • total market cap of all crypto in USD

But I cannot figure out how to get the current supply of BTC, ETH or anything else. Or just the ready-made market cap directly.

2 Answers 2


You can't get it because it's not there.

Circulating supply is total supply minus tokens that are not circulating. Tokens that are not circulating are stored in addresses, like any other token. The difference is the addresses are convincingly out of circulation which requires a human review. It is subjective. Providing a list of those addresses and why they should be counted as uncirculating is part of the onboarding process for reporting sites such as coinmarketcap.

Price is also subjective. It's what someone is willing to pay for it. An ERC20 contract defines what it is. An app defines what you can use it for. An exchange discovers what someone is willing to pay for it.

There is a possibility of using an automated market maker such as Uniswap to discover a price. That is contingent on a liquidity pool existing and your assessment of how deep (and reliable) the price quote is. Other subtleties exist around the reliability of such quotes because such pools are vulnerable to price-manipulation attacks by wealthy attackers and coders using flash loans. Generally, one needs to use defensive patterns to avoid trouble. Bad assumptions about price quotes are responsible for a parade of DeFi hacks.

Hope it helps.

  • Maybe I used the term "circulating" incorrectly. What I meant was just total number of coins minted until now minus any burnt coins. E.g. etherscan.io/stat/supply provides total supply and market cap. I want to get those numbers from my contract. Oct 3, 2021 at 22:51
  • The totalSupply() figure normally reports that. mint() and burn(), if they exist, adjust it accordingly. Oct 7, 2021 at 22:30
  • Thanks Rob, however that only works for ERC-20 tokens, right? Is there a way to get the same numbers for a) ETH itself b) other coins like BTC, DOT, ADA? Oct 12, 2021 at 1:19
  • Correct - ERC20. You might find you need an Oracle to gather everything you need. Oct 12, 2021 at 5:00

You can make a request with Tellor (docs.tellor.io). They're an oracle that allows retrieval of any kind of data. They currently don't push mkt cap or total supply on-chain, but that's just because no one else has requested it. Would be super simple though

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.