question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calling a function with nested structs

See original GitHub issue

@ricmoo do you have an example of how to use the new ABI encoder released in Solidity 0.4.19? I’m particularly interested in how to pass in nested structs as a parameter. For example, how to call addTestStruct in the following example contract using Ethers.js

pragma solidity 0.4.19;
pragma experimental ABIEncoderV2;

contract TestContract
{
    struct SubStruct {
        uint256 id;
        string description;
    }

    struct TestStruct {
        uint256 id;
        string description;
        SubStruct subStruct1;
    }

    TestStruct[] public tests;

    function addTestStruct(TestStruct testStruct) public
    {
        tests.push(testStruct);
    }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:22 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
ricmoocommented, Dec 4, 2017

It doesn’t support named parameter yet (mostly because I haven’t written test cases yet), but you can do this:

var value = [
    someId,
    someDescription,
    [
        subId,
        subDescription
    ]
];
contract.addTestStruct(value);

It is a very simple change to add names, I just need to make sure it works, so need to test it. After that, you can do:

var value = { id: someId, description: someDescription: subStruct1: { id: subId, description: subDescription }};
contract.addTestStruct(value);
2reactions
ricmoocommented, Jan 11, 2018

This is fixed in https://github.com/ethers-io/ethers.js/commit/df930103e75dd89c9f6c14acda857a07f1b0d70c with test cases added for computing method signatures in general.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested Structure in C with Examples - GeeksforGeeks
1. By separate nested structure: In this method, the two structures are created, but the dependent structure(Employee) should be used inside the ...
Read more >
C function to modify the value of a nested struct?
The ModifyEngSpeedSampleRate() function above cannot be called with a pointer to the ASREngCtrlActive member because it has the wrong type.
Read more >
Nested Structure in C Programming Language Tutorial
In this tutorial, you will learn about Nested Structures in C Programming language.A Structure is a collection of similar elements.
Read more >
Nested structure in C - Javatpoint
Just like other variables, a structure can also be passed to a function. We may pass the structure members into the function or...
Read more >
Nested Structures in C - C Programming Tutorial - OverIQ.com
Here the first member is of type struct person . If we use this method of creating nested structures then you must first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found