1

I have a function in a smart contract I'm trying to call with call.

function doStuff(bytes[] calldata data) external payable {

To call it, I'm running:

bytes[] memory dataArray = new bytes[](1);
(bool success, bytes memory returnData) = CONTRACT_ADDRESS.call(
            abi.encodeWithSignature("doStuff(bytes[])", dataArray)
        );

But I keep getting:

TypeError: This type cannot be encoded.
            abi.encodeWithSignature("doStuff(bytes[])", dataArray)

At compile time. How can I fix this?

1 Answer 1

1

What Solidity version are you using?

I'm using Solidity version 0.8.16 and it's working fine for me.

Check:

pragma solidity ^0.8.16;

contract DoStuff {

    event DidStuff(uint256 timestamp);

   function doStuff(bytes[] memory _data) public {

        // Doing stuff..

        emit DidStuff(block.timestamp);
    }

}

contract Contract {

    address CONTRACT_ADDRESS;

    constructor(address doStuffAddress) {
        CONTRACT_ADDRESS = doStuffAddress;
    }
    
    function doIt() public {

        bytes[] memory dataArray = new bytes[](1);
(bool success, bytes memory returnData) = CONTRACT_ADDRESS.call(
            abi.encodeWithSignature("doStuff(bytes[])", dataArray)
        );

    }

}

Tested from Remix (I'm not sure what you are using):


[block:6 txIndex:0]from: 0xE81...4429Eto: Contract.doIt() 0xD8C...97aA9value: 0 weidata: 0xb29...f0835logs: 1hash: 0xb07...8bdeb
status  true Transaction mined and execution succeed
transaction hash    0x1ed0efca8ae04b6023af938acb6f2ba87dc066708d30bbe45d1884e18470d34d
from    0xE81903819F26C76C33f6f35967A56ca545f4429E
to  Contract.doIt() 0xD8C3fA537fc8FBe442E007759207cdd3AA997aA9
gas 27547 gas
transaction cost    27547 gas 
input   0xb29...f0835
decoded input   {}
decoded output   - 
logs    [
    {
        "from": "0xB5c6870320fEDcE225116588aD29dc4cCd988770",
        "topic": "0x492037fdabb4ac5a9b4e72edb0de0d83013611c4a53b457573d0d085f9222296",
        "event": "DidStuff",
        "args": {
            "0": "1665669544",
            "timestamp": "1665669544"
        }
    }
]
val 0 wei
1
  • 1
    0.7.6. I see... Looks like they updated. Wonder what version this fails on. Thanks! Oct 13, 2022 at 16:49

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.