应用程序二进制接口(Application Binary Interface,ABI)是用于处理智能合约的数据编码方案。ABI中定义的类型与使用Solidity编写智能合约时所用的类型相同。
abi
包中包含了ABI的编码/解码库。
ABI解码
以 function totalSupply() public view returns (uint256)
为例:
public BigInteger totalSupply() {
//Construct the function
Function totalSupply = new Function("totalSupply",
Collections.emptyList(), Arrays.asList(new TypeReference<Uint256>() {}));
//call the function
TransactionExtention txnExt = client.constantCall(Base58Check.bytesToBase58(ownerAddr.toByteArray()),
Base58Check.bytesToBase58(cntrAddr.toByteArray()), totalSupply);
//Convert constant result to human readable text
String result = Numeric.toHexString(txnExt.getConstantResult(0).toByteArray());
return (BigInteger)FunctionReturnDecoder.decode(result, totalSupply.getOutputParameters()).get(0).getValue();
}
当合约为JST时(精度18),结果如下:
Total Supply: 9900000000000000000000000000