I am receiving the "stack too deep" error when compiling my smart contract. I know it has to do with too many variables, and I've heard of creating a memory array to "group" variables together. I'm looking for an example of this in a struct that I can follow. I can post code if it would help. Thanks, Rob

  • You should post your code. Someone will probably help you sort it out. Aug 1, 2018 at 4:02

1 Answer 1


You can do something like this. But you should be aware that using memory is more expensive than simple stack.

pragma solidity ^0.4.0;
contract Ballot {

    struct Voter {
        uint weight;
        bool voted;
        uint8 vote;
        address delegate;

    function foo(bool d) public pure returns (uint) {
        Voter memory votes;
        votes.weight = 123;
        votes.voted = true;
        votes.delegate = msg.sender;
        votes.vote = 1;
        if (d) {
            votes.weight += 11; 
        } else {
            votes.vote = 2;
        return votes.weight + votes.vote;

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.