0

I am trying to test abi.encodeCall on Remix. I have this function

function getTestData() external pure returns (bytes memory){ // passing empty args () return abi.encodeCall(TargetContract.send,()); }

this is the version

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;

1 Answer 1

0

This is a bug (actually lack of feature) that has been fixed since Solidity 0.8.12: Release note: "General: Support ContractName.functionName for abi.encodeCall, in addition to external function pointers.". The fix is to change your version pragma like below.

pragma solidity ^0.8.12;
contract TargetContract{
    function send() external {}
}
contract Test{
    function getTestData() external pure returns (bytes memory){
        return abi.encodeCall(TargetContract.send,()); 
        // another solution: return abi.encodeWithSelector(TargetContract.send.selector, (""));
    }
}

You can also use the alternative in the comment (using abi.encodeWithSelector), it can also work for solc version before 0.8.12.

Your Answer

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

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