0

I am just struggling to understand why the constructor is done like it is and what is it doing?

I am trying to implement something similar as am looking to find the address of the contract, called DiceGame in this example.

Code snippet

2 Answers 2

0

Here, the constructor is asking for an address called diceGameAddress which will, hopefully, will be deployed DiceGame contract.

Now the line diceGame = DiceGame(diceGameAddress) is actually creating an instance of this deployed contract in this contract to be used later.

And finally, the address is being updated in the dice variable.

0
0

Your constructor should be

contract RidgeRoll is Ownable {
    DiceGame public diceGame;

    constructor(DiceGame diceGameAddress) {
        diceGame = diceGameAddress;
    }
}

then you can the functions of DiceGame inside RidgeRoll like this :

function use() public {
    diceGame.functionToUse();
}
0

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.