0

I saw a similar question here which I tried to use in my example but I still get confused from the code. Can you tell me what is the difference between those two examples?

contract First {

struct Emission {
    string accountIdHash;
    string orderIdHash;
}

function getData(string memory _orderIdHash) public view returns (string memory,string memory)
{
    return (
        "Account1",
        "Order1"
    );
  }
}

interface IFirst {
   function getData(string memory) external view returns (
        string memory,
        string memory
    );
 }

contract Second {

address contractFirst;

struct Emission {
    string accountId;
    string orderId;
}

Emission emission;

constructor(address _addressContractFirst)
{
    contractFirst = _addressContractFirst;
}

function mint(string memory _orderIdHash) public {

 
  (string memory accountIdHash, string memory orderIdHash) = IFirst(contractFirst).getData(_orderIdHash);

   emission = Emission(accountIdHash, orderIdHash);
}
}

And this example:

 function mint(string memory _orderIdHash) public {

 Emission memory emission = Emission(IFirst(contractFirst).getData(_orderIdHash));

 }

For me they are absolutely the same but in the second example Solidity throws an error saying that:
Wrong argument count for struct constructor: 1 arguments given but expected 2.

1 Answer 1

1

As the error says, you're passing only one argument (a tuple of 2 elements) to the getData function, while it needs 2 arguments.

And it seems solidity to not expand tuple to arguments.

That's why the first mint function works : first the tuple is broken down into 2 distinct elements accountIdHash and orderIdHash, and then passed as 2 separated arguments.

I found the exact same thing you are trying to do in an issue/feature request on the Solidity Repository : https://github.com/ethereum/solidity/issues/9600

It seems this has been requested, seen by the Solidity team (cameel) but not implemented.

1
  • Thank you, it looks like that solidity team should work on improving that. :)
    – Dakata
    Nov 27, 2022 at 0:25

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.