Error while generating smart contracts which returns array of struct in Web3j v3.3.1

0 votes
pragma solidity ^0.4.21;

pragma experimental ABIEncoderV2;

function getPurchaseOrderForVendor(string vendorNameInput) constant returns (PurchaseOrderStruct[])

I am returning an array of struct from solidity function as given above. It is compiled to abi and bin files. The issue is with creating wrapper files for the contract using web3j(v3.3.1). I'm getting the below errors:

Generating com.contract.InvoiceSettlement_sol_InvoiceSettlement ... 
Exception in thread "main" java.lang.UnsupportedOperationException: 
Unsupported type
encountered: tuple
    at org.web3j.abi.datatypes.generated.AbiTypes.getType(AbiTypes.java:221)

    at org.web3j.codegen.SolidityFunctionWrapper.buildTypeName(SolidityFunct
ionWrapper.java:851)
Jul 26, 2018 in Blockchain by sabby
• 4,350 points
266 views

1 answer to this question.

0 votes

Solidity does not support returning structs in external calls. It is only allowed in internal function calls. You need to decompose the struct and return the elements via a tuple.

You need to either return strings as bytes32, or (my preferred approach) you use one function to return the size of the array you want and have your retrieval function take in an index parameter and return one decomposed struct element at a time.

answered Jul 26, 2018 by Perry
• 17,020 points

Related Questions In Blockchain

0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
155 views
+1 vote
1 answer
0 votes
1 answer

How to set web3 solidity variable value?

The setLog transaction has not yet been mined by ...READ MORE

answered Jul 6, 2018 in Blockchain by Christine
• 15,790 points
139 views
0 votes
1 answer
0 votes
1 answer

How do I send back ethers to the sender of the tokens in a smart contract?

Whenever a smart contract receives ether via ...READ MORE

answered May 30, 2018 in Blockchain by Perry
• 17,020 points
416 views
0 votes
1 answer

Error while running make command using Fabric 1.0.6

It's a known issue in go 1.9.4: https://github.com/golang/go/issues/23739 While ...READ MORE

answered Jun 26, 2018 in Blockchain by Perry
• 17,020 points
112 views