Search code examples
javaethereumgethweb3-java

How to extract data from "RemoteCall<BigInteger>" return type function in java/kotlin?


I'm trying to read balance of an address from erc20 token contract using web3j. I've already generated java equivalent contract file. In this file, A function is returning RemoteCall type of object. Now, how to parse this output so that I can simply get the number (Big integer value)?

When I try to log the output using android log, I get some sort of encrypted output -

org.web3j.protocol.core.RemoteCall@48c4d84

Now I'm totally confused what to do next?

public RemoteCall<BigInteger> balanceOf(String param0) {
    final Function function = new Function(FUNC_BALANCEOF, Arrays.<Type>asList(new Address(param0)),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    return executeRemoteCallSingleValueReturn(function, BigInteger.class);
}

Expected output is of a Big Integer type number(token balance of the address).


Solution

  • You need to call send() on the instance of the RemoteCall<BigInteger> that is returned from balanceOf():

    RemoteCall<BigInteger> remoteCall = someObject.balanceOf(someParameter);
    BigInteger result = remoteCall.send();