2

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.

Sparky
  • 21
  • 2

1 Answers1

3

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! :

  • I entered in all the info with the runContractFunction link you provided and im getting this error message "message": "Cannot read properties of undefined (reading 'inputs'), Function `totalSupply` not found in ABI"? – Sparky Feb 19 '23 at 16:11
  • Also, is there an example with Java calling Moralis API? Not sure how I would go about doing that? – Sparky Feb 19 '23 at 16:42
  • I'm not entirely sure in Java, not familiar with the language entirely, you can check out the post here https://stackoverflow.com/questions/3913502/restful-call-in-java For the page, looks like there's been a bug in docs since I was able to execute the function myself. I'll report this to Moralis. – Yoseph Kurnia Soenggoro Feb 20 '23 at 01:38