通过web3j java获取ERC20代币的totalSupply是否有方法?

huangapple go评论53阅读模式
英文:

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

问题

我正在使用Android Studio开发一个Android应用程序。我已经实现了Web3j,并成功连接到以太坊使用Infura。我不确定如何获取特定代币的总供应量。

尝试使用load方法加载特定代币的合同,但未能使其正常工作。

英文:

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

得分: 3

不要回答我要翻译的问题。以下是翻译好的内容:

建议您使用 Moralis 而不是像 Infura 这样的 RPC 节点,因为 Moralis 提供了一个简单的 API,您可以在 Java 中调用它。它是一个基本的 REST API,因此您也可以在任何其他语言中调用它。

您可以在这里使用 runContractFunction API。您所需做的只是提供以下输入参数:

  • address:ERC20 代币合约地址
  • chain:您的 ERC20 代币所在的链
  • function_nametotalSupply
  • abi:ERC20 代币的 ABI

一旦您完成所有设置,您就可以仅需几行代码就能获取总供应量。

希望这对您有所帮助! 😊

英文:

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

huangapple
  • 本文由 发表于 2023年2月19日 00:03:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75494579.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定