web3j调用智能合约传数组参数

JerryZhou_ 2019-07-24 04:20:22

合约大概是这样的,需要两个数组参数:
* 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 "";
}
}
...全文
1339 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
一只区块链 2020-12-09
  • 打赏
  • 举报
回复
这个终于搞出来了
Sunyiban 2019-07-24
  • 打赏
  • 举报
回复
你这属于对接的三方吧。。看看API呗

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧