0

I was playing with this post code example:

function random() private view returns (uint8) {
       return uint8(uint256(keccak256(block.timestamp, block.difficulty))%251);
   }

But I'm always getting this error:

TypeError: Wrong argument count for function call: 2 arguments given but expected 1. This function requires a single bytes argument. Use abi.encodePacked

Any ideas? Thanks in advance. I don't find too much info about this issue.

0

As the error says, you need to use abi.encodePacked:

function random() private view returns (uint8) {
    return uint8(uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty)))%251);
}

More info about ABI Encoding and Decoding Functions.

Your Answer

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

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