Get Erc20 Token Supply using Web3API

Hi everyone, I was wondering if the was a way to get the total supply of an erc20 token using the Moralis web3API.

I don’t know of a way to get that now

You can use runContractFunction to call the totalSupply function on the ERC20 contract.

const ABI = [
  {
    constant: true,
    inputs: [],
    name: 'totalSupply',
    outputs: [
      {
        name: '',
        type: 'uint256',
      },
    ],
    payable: false,
    stateMutability: 'view',
    type: 'function',
  },
];

const options = {
  chain: 'eth',
  address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // wETH
  function_name: 'totalSupply',
  abi: ABI,
};

const totalSupply = await Moralis.Web3API.native.runContractFunction(options);
console.log('totalSupply', totalSupply);
2 Likes

Thanks this was very helpful