June 5, 2023

Context (matters)

How to make a Scavenger Hunt Part 2: Building Phase

Making a Scavenger Hunt

Part 2

In the second part of  How to make a Scavenger Hunt, we are going to focus on the tech stack needed and how Mentaport takes care of all the hard parts for you. 

Deploying a scavenger hunt with Mentaport takes four steps:

  1. Setting the contract
  2. Adding the contract rules
  3. Integrating our SDK into your app
  4. Deploying / activating contract

We will be using both the Core and the Supplement Mentaport SDKs in this tutorial. We are finishing our admin web portal, which will help make the contract creation and adding rules much easier in the near future, but for now, we are going to jump into code. 

Grab the spreadsheet you made in Part 1, and let's get started!

Setting the Contract

We will create our contract using Mentaport’s Supplement SDK. This function takes three parameters: ContractName, ContractType, and BlockchainTypes.

For this Scavenger Hunt, we are going to be minting NFTs live, so for ContractType, we pick Blockchain. The other type that can be used is Mintlist, which is used if you want to create a mintlist before the release of your collection.  

Mentaport is currently live in three chains: Ethereum, Polygon, and Sui. For this tutorial, we are going to use Ethereum for BlockchainTypes.

Adding the Rules

Once the contract is created, we are going to add the rules from your spreadsheet from Part 1. We will need the name, description, starting time and duration of the hunt, and the count of NFTs we want to drop. In this tutorial, we are going to only allow 100 NFTs to be found, and you will also set a time window for the hunt of one day.

We will use two important functions:

  • createMintRules to mint NFTs
  • createDynamicRules to update NFTs

Mentaport supports different types of contract rules. You can decide between minting a new NFT in each clue or dynamically updating the original NFT to show the progress. Both are very easy to implement with our infrastructure. In the code snippet below, we are adding the first three clues of the spreadsheet. As you can see, the first one is a mint event and the other two are dynamic updates.

If you make all the functions createMintRules, in each step, you will mint an NFT. If you make functions createDynamicRules you will update an NFT. If you look closer at the code, the main difference in the createMintRules and createDynamicRules functions is the type of rule being generated.

Take a look at both functions so you can see how the rules are being made. And this is all that is needed for you to add as many rules as you want to your Scavenger Hunt! 

Integrating with the SDK

In this part, we are going to add Mentaport SDK to your application. This way, you will be able to securely verify the location of each mint event and execute the rules you just created (mints and dynamic updates).

We will go over three important functions:

  • StartGeoLocation which starts location verification
  • getClosestTrigger to update each player throughout the game
  • checkMintStatus to validate locations and rules
  • triggerMint to award an NFT

The main function that starts location verification is called StartGeoLocation It takes two main parameters: isMobile and walkTime. isMobile should be true if users are only allowed to mint or update on mobile. walkTime is how long the user has to be at the precise location before allowing them to mint or update.

Once location verification starts, you can initiate the event triggers. These allow you to dynamically update individual NFTs according to the context of each player (like the location and time they are at). One of the many helper functions is `getClosestTrigger`. This function will return the closest event triggers to a player. This way, you can inform the players how far and in what direction they should go to find the closest NFT.

The third function you will need is the minting function. You can always call ‘checkMintStatus’ to verify the players are in the correct location and also to check that the rules are still active. Once you call ‘triggerMint’, if the rules pass successfully, the user will be able to mint the NFT on their mobile! 

We have both React and Next.js providers to integrate Mentaport’s SDK and make it easier for you.[link]

Deploying / activating the Contract

The last step is to activate and deploy your blockchain contract. During Mentaport’s Private Beta SDK we have the functionality to deploy one of our contracts for you and then transfer the ownership of the contract to your wallet. 

If you want to deploy your own contract, let us know!  We can walk you through the integration.

For more information, check our documentation. Looking forward to seeing your Scavenger Hunts!