6

I have a function that looks like this:

function foo(uint _someVar, bytes calldata _data) public {
    ...
}

Then I make a call to it from another function with "" as _data:

foo(123, "");

"" seems to be the default way to pass blank bytes. However, I get this truffle compilation error:

TypeError: Invalid type for argument in function call. Invalid implicit conversion from literal_string "" to bytes calldata requested.

I have tried to declare and pass variables, but it all comes down to trying to assign blank calldata bytes. Any tips on how to do this?

2
  • 4
    Use new bytes(0).
    – Ismael
    Commented May 3, 2021 at 7:52
  • This does not work in Solidity 0.8.24. Commented Mar 18 at 6:40

2 Answers 2

3

Try to use "0x". It helps me.

2
  • This worked. It's so stupid that an empty string won't. Commented Jul 8, 2023 at 23:30
  • This does not work in Solidity 0.8.24. Commented Mar 18 at 6:40
3
bytes memory data = new bytes(0);
1
  • 1
    While this seems to answer the question, please avoid code only answer. Commented Jun 18, 2022 at 4:07

Your Answer

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

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