i used web3j-java call Tether contract method balanceOf(the server node is mine , and on ether mainnet),my address has 3USDT,but i call balanceOf , the node returns me 0x as the balance value,it is not correct ,and how to resolve this problem. the geth version is 1.9.24 . block-chain had been sync finished.
my eth node start firewall,is someone help me to solve this problem,please contact me. and provide you more info about this.
Contract Address is: 0xdAC17F958D2ee523a2206206994597C13D831ec7
My Address is: 0xf19c930fad206da25f89a6b740fb1fdb403b351c
geth process: /root/eth/geth --http --allow-insecure-unlock --http.addr 0.0.0.0 --http.api admin,debug,web3,eth,txpool,personal,ethash,miner,net --http.corsdomain "*" --http.vhosts "*"
goals: get address USDT balance under Thether Token
codes:
Web3j web3j = Web3j.build(new HttpService("http://27.102.106.58:8545"));
List<Type> inputParameters = new ArrayList<>();
Address address = new Address("0xf19c930fad206da25f89a6b740fb1fdb403b351c");
inputParameters.add(address);
List<TypeReference<?>> outputParameters = new ArrayList<>();
TypeReference<Uint256> typeReference = new TypeReference<Uint256>(){};
outputParameters.add(typeReference);
Function function = new Function("balanceOf", inputParameters, outputParameters);
String encodeFunction = FunctionEncoder.encode(function);
org.web3j.protocol.core.methods.request.Transaction transaction = org.web3j.protocol.core.methods.request.Transaction
.createEthCallTransaction("0xf19c930fad206da25f89a6b740fb1fdb403b351c", "0xdAC17F958D2ee523a2206206994597C13D831ec7", encodeFunction);
EthCall ethCall;
BigInteger balanceValue = BigInteger.ZERO;
try {
ethCall = web3j.ethCall(transaction, DefaultBlockParameterName.LATEST).send();
List<Type> results = FunctionReturnDecoder.decode(ethCall.getValue(), function.getOutputParameters());
balanceValue = (BigInteger) results.get(0).getValue();//here is 0x
System.out.println(balanceValue);
} catch (Exception e) {
e.printStackTrace();
}