2

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?

1
3

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, privacy policy and cookie policy

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