pragma solidity ^0.4.17;

contract Lottery{

    address public manager; 
    address[] public players;

    function Lottery() public {
        manager = msg.sender;


    function enter() public payable{
        require (msg.value > 0.01 ether);

    function random() public view returns (uint){
        return uint(keccak256(block.difficulty, now, players));


I executed random function after being deployed on Rinkeby testnet, but no ether has been deducted as GasFee. Please correct me if i am wrong, but random functions is calculating a Psudorandom function and it involves computations. Shoudnt it require gas to execute?

One guess: Any view function which doesnt change state doesnt need Gas?



Clients have the option, but most clients will call the function in a read-only fashion, seeing that there is nothing for the network to verify because it doesn't change the state.

More details: When to use "View" and "Pure" in place of "Constant"

Hope it helps.

  • 1
    Now, I get it. Since it doesnt change state..it doesnt needs to be replicated to other machines which means no verification needed. Even if i would like to make 1000s request to this function in a second, they can only be made to my copy of Blockchain on my server or machine. Isnt it? Jan 25 '19 at 19:57
  • Yes, given that it's read-only, your own node can inspect the local copy of the chain (which it presumes is the same as everyone else's) and evaluate and respond. There are non-obvious subtleties, so I linked the other answer and the blog post. The blog post unpacks the issues people tend to get confused about. Jan 25 '19 at 20:01

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.