1

I'm a new developper on Solidity and maybe this is a trivial question but it is a crucial point for my project.

Is there any way to get the total supply of any ERC20 token (WBTC, and others) on Solidity ? Should I use an oracle ? Or do you have any other idea that I would not have though of ?

Thank you very much !

4

You just need to know the address of the ERC20 token and execute function totalSupply().

If you want to have that in a simple contract, you could have something like this:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";

contract Test {
    IERC20 public token;

    function getTotalSupply(address addr) public view returns(uint256) {
        return IERC20(addr).totalSupply();
    }
}

You certainly need to know the address of the ERC20 tokens you may want to check, so you have to know that beforehand and if necessary, store it in your contract within a list.

1
  • 1
    youre the man... im all back to 2013 with my ethSO score, this sucks makes me feel like a chump again – lopezdp Jul 16 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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