Home > Back-end >  Web3j call smart contracts the array parameters
Web3j call smart contracts the array parameters

Time:12-10


Contract, probably need two array parameters:
* Method: ` setMultiPlyRewardInfo (address [] the memory plyAddrs, uint256 [] the memory _rewards) public onlyManager ` ()

Now the problem is how to Java parameter to it, the code is such, complains

Public static String setMultiPlyRewardInfo () {
Try {
String privateKey_="123456";
String contractAddress_="111111";

Credentials Credentials=Credentials. The create (privateKey_);
String fromAddress=credentials. GetAddress ();

EthGetTransactionCount EthGetTransactionCount=web3j
EthGetTransactionCount (fromAddress, DefaultBlockParameterName. The LATEST). SendAsync (). The get ();
BigInteger nonce=ethGetTransactionCount. GetTransactionCount ();

List InputParameters=new ArrayList<> (a);

Address [] Address={new Address (" 0 x092754... "), and the new Address (" 0 x2b6186... ")};
Uint256 [] theBalance={new Uint256 (10), a new Uint256 (20)};

//join complains here
InputParameters. Add (arrays.aslist (address));
InputParameters. Add (arrays.aslist (theBalance));

List OutputParameters=new ArrayList<> (a);
TypeReference Result=new TypeReference () {};
OutputParameters. Add (result);

The Function Function=new Function (" setMultiPlyRewardInfo, "
InputParameters outputParameters);
String encodedFunction=FunctionEncoder. Encode (function);

RawTransaction RawTransaction=RawTransaction. CreateTransaction (nonce,
The Convert. ToWei (" 1 ", the Convert. Unit. GWEI). ToBigInteger (),
New BigInteger (" 5000000 "), contractAddress_, encodedFunction);

Byte [] signedMessage=TransactionEncoder. SignMessage (rawTransaction, 18928, credentials);
String hexValue=https://bbs.csdn.net/topics/Numeric.toHexString (signedMessage);

EthSendTransaction EthSendTransaction=web3j. EthSendRawTransaction (hexValue) sendAsync (). The get ();
Return ethSendTransaction. GetTransactionHash ();
{} catch InterruptedException (e)
e.printStackTrace();
return "";
} the catch (ExecutionException e) {
e.printStackTrace();
return "";
}
}

CodePudding user response:

This belongs to the docking of the three parties, you, look at the API bai

CodePudding user response:

This is finally out
  • Related