0

My struct

 struct UserIdea {
        string area;
        string path;
        string ideaType;
        string ideavalue;
        string amountValue;
        string ideaVerifiedThrough;
        address user;
        string firstIdeaID;
        string secondIdeaID;
        string comment;
        string ideaFromWebsite;
        string ideaReplaces;
        string counterIdea;
        uint256 createdAt;
    }

My Method:

 function createIdea(
        string calldata area,
        string calldata path,
        string calldata ideaType,
        string calldata ideaValue,
        string calldata amountValue,
        string calldata ideaVerifiedThrough,
        address user,
        string calldata firstIdeaID,
        string calldata secondIdeaID,
        string calldata comment,
        string calldata ideaFromWebsite,
        string calldata prevContent,
        bytes calldata signature
    ) external {
        // this recreates the message that was signed on the client
        bytes32 messageHash = toEthSignedMessageHash(
            keccak256(
                abi.encodePacked(
                    area,
                    path,
                    ideaType,
                    ideavalue,
                    amountValue,
                    ideaVerifiedThrough,
                    user,
                    firstIdeaID,
                    secondIdeaID,
                    comment,
                    ideaFromWebsite,
                    prevContent
                )
            )
        );
        require(
            recoverSigner(messageHash, signature) == user,
            "Signature error."
        );
        _internalCreateIdea(
              area,
                    path,
                    ideaType,
                    ideavalue,
                    amountValue,
                    ideaVerifiedThrough,
                    user,
                    firstIdeaID,
                    secondIdeaID,
                    comment,
                    ideaFromWebsite,
                    prevContent
        );
    }

This gives me CompilerError: Stack too deep, try removing local variables. error. What is the best way to resolve this. I know i have got so many fields in struct but i need them and I need to have datatype as string for most of them.

1 Answer 1

0

Did you forget to actually use the struct?

You are defining a struct, but it doesn't help unless you take it into use. So your function signature should be something like function createIdea(UserIdea calldata idea, string calldata prevContent, bytes calldata signature)

5
  • Actually _internalCreateIdea this internal method accepts the params and set it to the struct properties. So struct is used inside the internal method .
    – NinjaMAN
    Commented Aug 17, 2021 at 5:26
  • The actual issue in my code is: My method createIdea has so many parameters of string datatype which i definitely need to pass inorder to set the values for UserIdeastruct.
    – NinjaMAN
    Commented Aug 17, 2021 at 5:29
  • My point was that you can't pass it that amount of strings. You have to pass them as struct - or gather them in multiple calls Commented Aug 17, 2021 at 5:40
  • Alright. Does latest version of solidity supports struct as params without ABIEncoderv2?
    – NinjaMAN
    Commented Aug 17, 2021 at 5:51
  • I guess not. But at least it's not experimental anymore. docs.soliditylang.org/en/v0.8.0/… Commented Aug 17, 2021 at 5:55

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.