I'm new to solidity and OOP. I'm trying to understand the code in this simple lottery game example:


I am confused when they call governance.randomness() in line 57 in Lottery.sol. but I don't see the randomness() function implemented any where in any of the contract files.

The answer below explains that the unimplemented function will be implemented in the contract provided in CEth cToken = CEth(_cEtherContract);


But in the GitHub lottery example, I see the function is no where declared in any of the contracts (lottery.sol, randomness.sol and governance.sol).

is the function initiated when governance contract's init() function is called and it sets the randomness state variable? or is there something I'm missing in the code?

1 Answer 1


For your randomness example it is important to know that Solidity generates getters for all public variables. In the governance contract there is a public variable randomness which generates the mentioned function as a getter: https://github.com/alphachainio/chainlink-lottery/blob/master/ethereum/contracts/Governance.sol#L6.

In general Solidity does not perform any check if a contract implements a specific interface when casting it to that interface. More info on this can be found here: How is an interface initialised? (there are quite some other questions also explaining this ;) )

  • I understand it creates a getter function for public variables. But Where is the init function from governance.sol called? I think this sets the randomness and lottery state variables?
    – toddash
    Commented Jan 11, 2022 at 2:15
  • It is just a getter, so until init is called the randomness() function will return the 0-Address, as this is the default value for uninitialized addresses.
    – Richard
    Commented Jan 11, 2022 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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