10

I have a contract on the Ropsten test network and I am trying to return an array of structs but I am receiving the following error in my JS console.

enter image description here

I am including the following at the top of my contract

pragma solidity ^0.4.18;
pragma experimental ABIEncoderV2;

and this is the function I am calling

 function getAllLand() external view returns (Land[]) {
        return landRegister;
    }

I know that this particular feature is experimental but any idea why this error might be thrown?

Thanks

  • I am facing issues in same contract method execution using web3js(1.0.0-beta.36). var abi = JSON.parse('[{"constant":false,"inputs":[{"name":"s","type":"string"},{"components":[{"name":"a","type":"uint256"},{"name":"b","type":"uint256"}],"name":"b","type":"tuple"}],"name":"foo","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"y","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"z","outputs":[{"name":"a","type":"uint256"},{"name":"b","type":"u – user2336139 May 20 at 14:31
  • It is found that web3js version was not correct. The issue is resolved with 1.0.0-beta.36. – user2336139 May 20 at 15:35
7

The error lies within the web3-object, not your smart contract. The struct feature is not yet implemented there.

See https://github.com/ethereum/web3.js/issues/1241 where this issue is described.

So basically you can work with solidity-structs when interacting with your contract-functions inside a contract or with a library, but not to pass data from web3 to your contract or to retrieve data from the contract through web3.

0

https://github.com/ethereum/web3.js/issues/1241 is solved and included in the release web3.js 1.0.0-beta.36. Now you can call Solidity functions with struct parameters.

Example from the issue:

Contract

pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2;

contract Test {

    struct Bar {
        uint a;
        uint b;
    }

    Bar public z;
    string public y;

    function foo(string s, Bar b) public {
        y = s;
    }

}

Javascript Call

contract.methods.foo("hello", [ 1, 2 ]).send({ from: '0x...' })

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.