0

I'm trying to call external function in contract B from contract A using staticcall. Here is code for contract A:

contract A {
    address public addr;
    bool public success;
    bytes public result;

function setAddr(address _addr) public {
    addr = _addr;
}


function callB(uint256 arg1, uint256 arg2) public {
    (success, result) = addr.staticcall(abi.encodeWithSignature("funcB(uint256, uint256)", arg1, arg2));
}

}

and here is contract B:

contract B {

  function funcB(uint256 arg1, uint256 arg2) public pure returns(bool) {
    if (arg1 > 10 && arg2 > 90) {
        return true;
    } else {
        return false;
    }
  }
}

but this doesn't work. Public bool "success" after calling callB still got value "false", and there is no data in "result".

But when there is only one argument like here:

contract A {
    address public addr;
    bool public success;
    bytes public result;

function setAddr(address _addr) public {
    addr = _addr;
}


function callB(uint256 arg1) public {
    (success, result) = addr.staticcall(abi.encodeWithSignature("funcB(uint256)", arg1));
}

}

and here:

contract B {

  function funcB(uint256 arg1) public pure returns(bool) {
    if (arg1 > 10) {
        return true;
    } else {
        return false;
    }
  }
}

everything works fine. I've got "true" in "success" and received data in "result" bytes.

What I'm missing here?

  • 2
    Fix that: funcB(uint256,uint256) without space. – alberto Jul 2 at 18:18
  • Thanks! It worked! I'm so angry that I have been bothering with it for two hours and the answer is so simple! – Cezary Stroczyński Jul 2 at 18:40
1

From the official documentation:

The first four bytes of the call data for a function call specifies the function to be called. It is the first (left, high-order in big-endian) four bytes of the Keccak-256 (SHA-3) hash of the signature of the function. The signature is defined as the canonical expression of the basic prototype without data location specifier, i.e. the function name with the parenthesised list of parameter types. Parameter types are split by a single comma - no spaces are used.

Note the ending statement: no spaces are used.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.