0
は、これは私がweb3Jを使用してスマート契約ラッパーを生成している私のプライベートネットワークweb3jは契約機能を使用していませんか?
contract AB {
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
/* Initializes contract with initial supply tokens to the creator of the contract */
function AB() {
balanceOf[msg.sender] = 1200; // Give the creator all initial tokens
}
/* Send coins */
function transfer(address _to, uint256 _value) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
balanceOf[msg.sender] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
}
function gettokenBalance(address to)constant returns (uint256){
return balanceOf[to];
}
}
の中に私の簡単な契約であると私は
ように私の契約機能にアクセスしようとしていたときにpublic Future<Uint256> gettokenBalance(Address to) {
Function function = new Function("gettokenBalance",
Arrays.<Type>asList(to),
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
return executeCallSingleValueReturnAsync(function);
}
のような機能があります
AB newAB = AB.load(contractaddress, web3j, credentials, gasprice, gaslimit);
Future<Uint256> result = newAB.gettokenBalance(new Address(address));
LOGGER.info("result:::"+result.get());
java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: 0
at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357) ~[na:1.8.0_91]
at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895) ~[na:1.8.0_91]
at com.belrium.service.UserWalletService.check(UserWalletService.java:197) ~[classes/:na]
at com.belrium.controller.UserController.check(UserController.java:119) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
助けてください。
web3jは、生成されたスマートコントラクトラッパーがAndroid用にJava 1.6互換である必要があるため、通常のFuturesを使用します。 JSON-RPC呼び出しとよく似た同期/非同期の選択肢を提供することを将来のリリースで期待しています。 –
@ConorSvensson Kotlinを見るのは興味深いかもしれません。Android上でサポートされており、古いJavaバージョンをターゲットにすることができます。私はまだそれを試していないが、それは非常に見栄えの良い非同期サポートを持っています。 – Jodiug