I am trying to call a smart contract transaction called “balanceOf” using the callSmartContractFunction method. The blanceOf function is as follows.
{ "constant": true,
"inputs": [ { "internalType": "address", "name": "account", "type": "address" } ],
"name": "balanceOf",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
the address in the inputs is the user account address and it should give the balance of a certain type of tokens as the output. I used the following method to get the result.
public void callMethod (EthereumAccount user) {
String encodedFunction = getEncodedFunction(user.getAddress());
etherService
.callSmartContractFunction(
user,
tonAddress,
encodedFunction
)
.setCallback(new ListenableFutureTask.Callback<String>() {
@Override
public void onSuccess(String result) {
List outputParameters = Arrays.asList(
new TypeReference<Uint>() {
});
Log.i(tag, "call method" + FunctionReturnDecoder.decode(result, outputParameters));
//success
}
@Override
public void onFailure(ExecutionException exception) {
//failure
}
@Override
public void onCancelled(InterruptedException exception) {
//cancelled
}
});
}
@NotNull
public String getEncodedFunction(String userAddress){
List<Type> inputParameters = Arrays.asList(new Address(userAddress));
List outputParameters = Arrays.asList(
new TypeReference<Uint>() {
}
);
Function transferFunction = new Function("balanceOf", inputParameters, outputParameters);
return FunctionEncoder.encode(transferFunction);
}
the result i get do not match the expected result. What is the correct way to call a smart contract function and get the result? I have looked over the Aerowallet example and I cannot find callSmartContractFunction anywhere. Thank you