4

Following is my code:

pragma solidity >=0.4.17;

contract Lottery {
    address public manager;
    address[] public players;

    constructor () public {
        manager = msg.sender;
    }

    function enter() public payable {
        require(msg.value > 0.01 ether);
        players.push(msg.sender);
    }

    function random() private view returns (uint256) {
        returns unit(keccak256(abi.encodePacked(block.difficulty, now, players)));
    }


}

And I am getting following error:

browser/ballot.sol:17:9: ParserError: Expected primary expression.
        returns unit(keccak256(abi.encodePacked(block.difficulty, now, players)));
        ^-----^

Current version is 0.5.1+commit.c8a2cb62.Emscripten.clang

How to resolve this error?

2
  • 3
    What is unit??? Feb 23, 2019 at 11:15
  • Hey man! I know it's been two years already, but I believe Rosco Kalis gave you a valid answer don't you think? Please accept the answer if it solved your problem. Thanks
    – mbappai
    Mar 21, 2022 at 7:15

1 Answer 1

6

The keyword you have to use to return a value is return, not returns. And as goodvibration mentioned, you probably meant to write uint, instead of unit. The following should work:

function random() private view returns (uint256) {
    return uint(keccak256(abi.encodePacked(block.difficulty, now, players)));
}

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.