PatrickAlphaC / hardhat-smartcontract-lottery-fcc

MIT License
118 stars 183 forks source link

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

Closed alimazhar4 closed 1 year ago

alimazhar4 commented 1 year ago

I am get the following error:

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

The line where this happened is:

        (bool upkeepNeeded, ) = checkUpkeep("");

The code is::

...
function checkUpkeep(
        bytes calldata /*checkData*/
    )
        public
        override
        returns (bool upkeepNeeded, bytes memory /*performData*/)
    {
       // ...
    }

    function performUpkeep(bytes calldata /*performData*/) external override {

        // error in the below line _______________________________!
        (bool upkeepNeeded, ) = checkUpkeep("");
        //________________________________________________________!

        if (!upkeepNeeded) {
            revert Raffle__UpkeepNotNeeded(
                address(this).balance,
                s_players.length,
                uint256(s_raffleState)
            );
        }
...

I converted the string to bytes using the following but it also didn't work:

        (bool upkeepNeeded, ) = checkUpkeep(bytes(""));

The error I get after doing this:

Error: Invalid type for argument in function call. Invalid implicit conversion from bytes memory to bytes calldata requested.solidity(9553)

How do I pass an empty parameter in bytes calldata format?

alimazhar4 commented 1 year ago

It was solved by changing the checkUpKeep function's parameter to bytes memory.

With Error:

function checkUpkeep(
        bytes calldata /*checkData*/
    )   
    ...

Without Error:

function checkUpkeep(
        bytes memory /* checkData */
    )   
    ...