I'm new to Ethereum and I got stuck on trying to call balanceOf on a deployed ERC20 contract.
Here is the code I have so far:
Web3j web3j = Web3j.build(new HttpService()); RemoteCall<BigInteger> customerBalance; Function function = new Function( "balanceOf", Arrays.asList(new Address(<address_of_the_account>, new ArrayList<>()); String encodedFunction = FunctionEncoder.encode(function); org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall( Transaction.createEthCallTransaction(<not_sure_what_the _FROM_address_is>, <not_sure_what_the_TO_address_is>, encodedFunction), DefaultBlockParameterName.LATEST) .sendAsync().get(); List<Type> result = FunctionReturnDecoder.decode( response.getValue(), function.getOutputParameters());
In the documentation (https://docs.web3j.io/transactions.html#querying-the-state-of-a-smart-contract) has a different signature (Transaction.createEthCallTransaction(contractAddress, encodedFunction), but that doesn't compile.
I'm on the 3.1.1 version of web3j (latest). I don't know what the to and from addresses are (in the documentation there's just one address which I assume is the deployed contract's address).