Solidity Interface – Understanding Contracts Calling Unimplemented Functions with Chainlink

chainlinkinterfacessoliditysolidity-0.6.x

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

https://github.com/alphachainio/chainlink-lottery/blob/master/ethereum/contracts/

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);

https://stackoverflow.com/a/64734548/4488843

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?

Best Answer

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 ;) )

Related Topic