Defined an interface

 interface ISafe {
 function encodeTransactionData(
    address to,
    uint256 value,
    bytes calldata data,
    Enum.Operation operation,
    uint256 safeTxGas,
    uint256 baseGas,
    uint256 gasPrice,
    address gasToken,
    address refundReceiver,
    uint256 _nonce
) external view returns (bytes memory);


When i am trying to access that, it is giving "CompilerError: Stack too deep, try removing local variables"

    bytes memory txHashData =  ISafe(msg.sender).encodeTransactionData(
                // Transaction info
                // Payment info
                // Signature info

How to fix the error?

3 Answers 3


What's the significance of the interface? is a necessity? if it isn't then i suggest you use a struct and push to the struct in the contract of the function you're interfacing. These errors occur when you have too much function arguments, local variables, or return values in a function. You can't reduce your function arguments, so pass the values in by pushing them to a struct instead. If you're not satisfied with this answer let me know.


This happens when you are using too many parameter in your external functions or too many return values. To avoid you can change scope of the method to internal. Refer to this article for more info.

  • Its an interface so cannot make the function internal
    – Dummy Mail
    Jan 28, 2023 at 14:39

The issue is that your function() is taking too many independent variables. To solve this, you can pack all (or some of them) into a structure.

So instead of your function receiving ten variables. It would receive a single struct with ten properties.

A simple example where I pack 24 values into a function call:

// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.3;

contract StackTooDeepSolution {

    // Struct containing eight variables
    struct Numbers {
        uint one;
        uint two;
        uint three;
        uint four;
        uint five;
        uint six;
        uint seven;
        uint eight;
    // A function call with 3 structures (8x3 = 24 variables)
    function addData(Numbers memory firstNum, Numbers memory secondNum, Numbers memory thirdNum) external view returns (uint sum) {

        sum = firstNum.one + firstNum.two + firstNum.three + firstNum.four + firstNum.five + firstNum.six + firstNum.seven + firstNum.eight;
        sum += secondNum.one + secondNum.two + secondNum.three + secondNum.four + secondNum.five + secondNum.six + secondNum.seven + secondNum.eight;
        sum += thirdNum.one + thirdNum.two + thirdNum.three + thirdNum.four + thirdNum.five + thirdNum.six + thirdNum.seven + thirdNum.eight;


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.