0

I would like to get information about token. For example total supply and so on. For this I need the contract. However what is the way to actually load it/access it from Java?

Checking examples in languages such as python, it seems trivial:

contract_address = 'CONTRACT_ADDRESS' 

abi = json.loads(abiJson)

contract = web3.eth.contract(address=contract_address, abi=abi)

totalSupply = contract.functions.totalSupply().call()

However how to actually do this using Java? Do I need to generate .abi file and then compile it to java? This way, wouldn't I need to recompile the project everytime I wanted to find info about another contract?

Thanks for help!

0

Web3j provides you with the ability to generate Java wrappers from ABI files for Solidity smart contracts. You can do so in different ways, mainly:

For your case, you can use the web3j-codegen module to generate the wrappers. Then, load the generated class dynamically.

Since you only need a set of predefined methods that follow ERC20 standard or similar. This might work for you.

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.