We are trying to use web3j for encoding the parameters for calling the solidity functions which are deployed in the private ethereum network. Call is done using JSON-RPC. We are able to encode the input parameters of the functions which have primitive attributes as input as of now successfully. And we are able to decode the primitive return parameters also using web3j. The examples in the web3j have listed them.

But I am not able to find anything which will let me call functions which have struct as input or return, like below ( They are from Ballot.sol from the Solidity site )

function giveRightToVote(address voter) external {..}

function vote(uint proposal) external {..}

How can I call these functions from web3j by passing struct type objects as input. Can anyone please suggest?

PS: I went through this post, but as I understand, the solidity function here is accepting individual primitive attributes.Not a struct Get the same result of abi.encode function in Java

1 Answer 1


you don't have to encode it. For a given struct

struct ExtData {
  address recipient;
  uint256 extAmount;

you can build the input in web3 like this:

       let  extData = {
        recipient: accounts[2].address,
        extAmount: web3.utils.toWei("1")

Then just call your function with the struct as the input

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.