Is there a way to get totalSupply of an ERC20 token using web3j java?

314 views Asked by At

I'm developing an android app using android studio. I implemented web3j and successfully connected to ethereum using infura. I'm not sure how I can get the total supply of a specific coin.

Tried using the load method to load a specific tokens contract but was not able to get that to work.

1

There are 1 answers

3
Yoseph Kurnia Soenggoro On

Instead of using RPC nodes like Infura, I recommend that you use Moralis as it provides you with an easy API that you can call in Java. It's a basic REST API so you can call it in any other language too.

You can use this runContractFunction API here. And all you need to do is provide the input parameters as follows:

  • address: ERC20 token contract address
  • chain: the chain your ERC20 token exists
  • function_name: totalSupply
  • abi: the ABI of ERC20 token

Once you have all this setup, you'll be able to get the total supply in just a few lines of code.

Hope this helps out! :