Solution: Part 1

Build our own play-to-earn game.

Inheritance structure

For clarity and code maintainability, we'll separate VRF-related code from the parts of our game that don't depend on randomness.

  • TreasureHuntNoVRF.sol is a base contract containing state variables and modifiers that don't depend on the VRF.

  • TreasureHuntVRF.sol will inherit from TreasureHuntNoVRF.sol and contain all VRF-related inheritance, state variables, and an override implementation of the VRF fullfillRandomWords() function. However, it will not implement the constructor inherited from the VRF contracts; we'll save its implementation for the last contract in our inheritance structure. Therefore, we'll have to declare TreasureHuntVRF.sol as an abstract contract.

  • TreasureHunt.sol is our final derived contract. Inheriting from TreasureHuntVRF.sol (and hence, from TreasureHuntNoVRF.sol), it will implement the constructor, game, and payment functions, as well as admin and security design patterns (ownability, pausability, and reentrancy guard).

Non-VRF-related base contract

First, we'll define a base contract TreasureHuntNoVRF.sol that contains the parts of our game that do not depend on randomness and Chainlink's VRF. Later we'll add those components in a separate contract TreasureHuntVRF.sol that will inherit from the present contract.

Get hands-on with 1200+ tech skills courses.