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:


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]; 

        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.