0

This is in reference to ERC 725 Identity Contracts. I am updating the contract to version 0.5. The issue arise in a specific function where it requires a single argument to the call method which I have provided using abi.encodePacked but receiving the following error

2 arguments given but expected 1. This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it.

For reference, I have added the code snippets

 struct Execution {
        address to;
        uint256 value;
        bytes data;
        bool approved;
        bool executed;
    }
function approve(uint256 _id, bool _approve) public returns (bool success) {
        require(
            keyHasPurpose(keccak256(abi.encodePacked(msg.sender)), 2),
            "Sender does not have action key"
        );

        emit Approved(_id, _approve);

        if (_approve == true) {
            executions[_id].approved = true;
            success = executions[_id].to.call(executions[_id].data, 0);
            if (success) {
                executions[_id].executed = true;
                emit Executed(
                    _id,
                    executions[_id].to,
                    executions[_id].value,
                    executions[_id].data
                );
                return;
            } else {
                emit ExecutionFailed(
                    _id,
                    executions[_id].to,
                    executions[_id].value,
                    executions[_id].data
                );
                return;
            }
        } else {
            executions[_id].approved = false;
        }
        return true;
    }

Getting the following error on this line of code

success = executions[_id].to.call(executions[_id].data, 0);

TypeError: Wrong argument count for function call: 2 arguments given but expected 1. This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it.

I have already tried the following solution

success = executions[_id].to.call(abi.encodePacked(executions[_id].data, 0))

But the issue still persists

  • 2
    Have you tried abi.encode(executions[_id].data, 0)? – Adam Boudjemaa Feb 25 at 22:32
  • Yes, I have also tried it like this success = executions[_id].to.call(abi.encode(executions[_id].data,0)); <br/> but receives the following error Type tuple(bool,bytes memory) is not implicitly convertible to expected type bool – Qasid Labeed Feb 26 at 6:57
  • @AdamBoudjemaa, According to breaking changes solidity documentation the .call() function only accepts a single byte argument which is not padded So abi.encode() will not be suitable here since it pads the arguments – Qasid Labeed Feb 26 at 7:32
  • 1
    @QasidLabeed Adam is right you have to use abi.encode() when calling another contract because you need to pad arguments. The new error is caused because call returns two values. You have to do something like (bool success, bytes result) = <address>.call(abi.encode(<params>));. – Ismael Feb 26 at 14:49
  • Thanks, Ismael, the issue is resolved. – Qasid Labeed Mar 8 at 9:21

Your Answer

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

Browse other questions tagged or ask your own question.