合約大概是這樣的,需要兩個陣列引數:
* Method: `setMultiPlyRewardInfo(address[] memory plyAddrs,uint256[] memory _rewards ) public onlyManager()`
現在問題是java這邊如何給它傳引數,目前寫的代碼是這樣,會報錯
public static String setMultiPlyRewardInfo(){
try {
String privateKey_ = "123456";
String contractAddress_ = "111111";
Credentials credentials = Credentials.create(privateKey_);
String fromAddress = credentials.getAddress();
EthGetTransactionCount ethGetTransactionCount = web3j
.ethGetTransactionCount(fromAddress, DefaultBlockParameterName.LATEST).sendAsync().get();
BigInteger nonce = ethGetTransactionCount.getTransactionCount();
List<Type> inputParameters = new ArrayList<>();
Address[] address = {new Address("0x092754..."),new Address("0x2b6186.....")};
Uint256[] theBalance = {new Uint256(10),new Uint256(20)};
//這里加入會報錯
inputParameters.add(Arrays.asList(address));
inputParameters.add(Arrays.asList(theBalance));
List<TypeReference<?>> outputParameters = new ArrayList<>();
TypeReference<Bool> result = new TypeReference<Bool>() {};
outputParameters.add(result);
Function function = new Function("setMultiPlyRewardInfo",
inputParameters,outputParameters);
String encodedFunction = FunctionEncoder.encode(function);
RawTransaction rawTransaction = RawTransaction.createTransaction(nonce,
Convert.toWei("1", Convert.Unit.GWEI).toBigInteger(),
new BigInteger("5000000"), contractAddress_, encodedFunction);
byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction,18928,credentials);
String hexValue = Numeric.toHexString(signedMessage);
EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).sendAsync().get();
return ethSendTransaction.getTransactionHash();
} catch (InterruptedException e) {
e.printStackTrace();
return "";
} catch (ExecutionException e) {
e.printStackTrace();
return "";
}
}
uj5u.com熱心網友回復:
你這屬于對接的三方吧。。看看API唄uj5u.com熱心網友回復:
這個終于搞出來了轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/232140.html
標籤:Java EE
上一篇:求大神幫忙,Springboot框架雙資料源查詢視圖資料不完整!!
下一篇:idea部署eclipse專案以后,原本在eclipse中運行正常的專案,傳入引數之后報java.lang.IllegalArgumentException
