0

How can I pass struct to Function I tried doing it but all in vain

struct testSruct
{

    uint size;
} 

function testFunc(  testSruct test) public returns(bool replaced)
{
    return true;
}

Getting error :

This type of error is only supported in new experimental ABI Encoder

0

You cannot pass a struct in/out of a function without using the experimental ABI encoder, which you should not do outside of experimentation.

What you can do is pass the individual members.

pragma solidity 0.5.0;

contract ABI {

    struct TestStruct {
        uint size;
    } 

    function testFunc(uint test) public pure returns(bool replaced) {
        return test == 0;
    }
}

With the experimental ABI:

pragma solidity 0.5.0;
pragma experimental ABIEncoderV2; // This will generate a cautionary warning.

contract ABI {

    struct TestStruct {
        uint size;
    } 

    function testFunc(TestStruct memory test) public pure returns(bool replaced) {
        return test.size == 0;
    }
}

Hope it helps.

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.