1

I am trying to create a struct as shown in the code below.

The function setData is intended to create an object of the struct, take the inputs (a string and a list of type bytes32[5]) and set their values. The code compiles perfectly. However, when I try to run the setData function with the inputs shown below, I get Gas estimation failed.

Test Inputs:

"0x9b461b19602cfe81c9ffb52d6983b7c39c5b3f97",["0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac0","0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac1","0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac2","0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac3","0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac4"],"Frank"

pragma solidity ^0.4.21;


contract Registration {

    struct staffMemberData {
        string name;
        bytes32[5] staffMemberAttributes;
    }

    mapping (address => staffMemberData) staff;
    address[] public staffMemeberAccts;

    function setData(address _address, bytes32[5] _attributes, string _fName) public {
        var s = staff[_address];

        uint256 arraylength = 5;
        uint8 x = 0;
        while(x < arraylength)
        {
            s.staffMemberAttributes[x] = _attributes[x]; 
            x++;
        }

        s.name = _fName;

        staffMemeberAccts.push(_address) -1;
    }


    function getData() view public returns (address[]) {
        return staffMemeberAccts;
    }    

}

What am I doing wrong? Is there a better way to do this to not consume as much gas?

  • I've tried your contract in remix and it work as expected. Transaction cost: 197187 gas. How are you calling your gas estimation? – Ismael Jun 3 '18 at 2:57

Your Answer

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

Browse other questions tagged or ask your own question.