0

I am struggling to figure out the abi.decode function when using it to decode the bytes coming as output from a reverted low level call to another contract. The way I am using it is by calling the CheckContract() function on contract A:

function CheckContract() public {
    require (!isContract(msg.sender),"No contracts allowed");}

from these two functions on contract B:

function checkWithDecode() public returns (bool, string memory) {
    (bool success, bytes memory data) = CheckerAddress.call(abi.encodeWithSignature("CheckContract()"));
    string memory reply = abi.decode(data, (string));
    return (success, reply);
}

function checkWithoutDecode() public returns (bool, bytes memory) {
    (bool success, bytes memory reply) = CheckerAddress.call(abi.encodeWithSignature("CheckContract()"));
    return (success, reply);
}

As expected, CheckContract reverts on both of the cases and the boolean is false. When called from checkWithoutDecode the transaction is successful and the output is:

{
    "0": "bool: false",
    "1": "bytes: 0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000144e6f20636f6e74726163747320616c6c6f776564000000000000000000000000"
}

However, when I attempt to run the decode method on the bytes I receive, using checkWithDecode, the whole transaction fails reverting just at abi.decode. Can anyone explain what is wrong with it? How should I decode that output?

Thanks in advance

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.