0

solidity 0.5.0 web3@ 0.20.7

In my contract.There's a function (view) returns a struct type. When I used web3.js to call this function, I got "Error: invalid solidity type!: tuple". I know that this problem is solved in web3@1.0.0-beta.36. But my Dapp is using web@0.20.7. I don't want to change to 1.0.0, because my app is not small. Is there a solution to this problem in web3 0.20.7? Thanks a lot.

  • 1
    Are we supposed to guess how you call this function from your web3 script??? BTW, there is no problem on web3.js v0.20.x, related to functions which return a tuple. You can change your contract's function to return a tuple instead of a struct. Otherwise, you'll need to switch to web3.js v1.x. In general, you should choose between [Solidity 0.4.x, Truffle 4.x, Web3 0.x] and [Solidity 0.5.x, Truffle 5.x, Web3 1.x]. – goodvibration Oct 24 at 10:31
1

You may use web3.eth.call function like this:

var myContract = new web3.eth.Contract (myContractABI, myContractAddress);
var result = web3.eth.call ({
  from: fromAddress, // Optional
  to: myContractAddress,
  data: myContract.methods.myMethod(... call parameters ...).encodeABI ()
});

Then you will need to somehow decode returned result yourself. To make this work with your version of web3js you may also need to manually edit you contract's ABI and change return type for your function from struct to nothing.

See documentation for details how structs are packed by ABI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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