🎮Games
The game contracts enable you to implement a play and earn mechanism around a game you or someone else deployed.
Here is a step-by-step guide to creating your own game:
Creating Your Game
Go to the Games page and click on the Create Game button
Fill in the form that pops up and validate the transaction. This will create your game. If you're planning to use an API to process your users' scores, you should set the game contract address variable to that of PaySwap's primary address (the address that owns the CanCan channel 1).
Tick the Mine Only button to only list your games in order to find the game you just created faster. If you can't find your game, reload the page and try again.
Setting Up Your Game
The next step is to update your game contract. Click on the Control Panel button in your betting contract's panel and then on the Update Game button. Fill in the form with the appropriate value for each parameter and validate the transaction
In the step after that, you need to update the link to play the game so users can play. In your control panel's menu, click on the Update Info button and fill in the form with the appropriate value for each field. Hovering your cursor over the help icon next to each parameter enables you to read a description of the parameter. Validate the form and confirm the transaction.
PaySwap uses the game API link to fetch scores by token ID so users can update their scores on the blockchain.
How To Play
Here is a step-by-step guide to playing games:
You first need to buy enough minutes to play. If you buy 30 minutes for instance, you have 30 minutes to get and submit a score from the game's site. Any score submitted after that will not be eligible for rewards from the game.
To buy minutes, go to your game's panel and click on the View Game button to go to the game's page. Click on the Mint new ticket button and validate the transaction to mint a game NFT which is necessary to play your game and claim rewards
After minting your game NFT, the last line in the image below on your game page should change from You have 0 tickets to You have 1 ticket(s) followed by a list of your ticket ids. Remember your ticket id as you will be needing it for most interactions with your game. Our ticket ID in the image below is 2
We can now buy minutes in our game, let's buy 30 minutes. To do so, click on the Play to Win button to go to the form in the image below. Fill in the form with enough tokens to buy the number of minutes you are willing to purchase and validate the transaction.
We inputted our game NFT ID which is 2 and enough tokens to buy 30 minutes in the game. The text Buy XX Minutes changes as you change the number of tokens to send
We now have to go play the game, get a score and submit that score before the 30 minutes expire or we would have lost our investment. At the top of the game page, you can view a Play Game button. Click on it to launch the game in a window
You can play the game from the pop-up or click on the link at the top of the pop-up to open the game in a new window
Once you get a score you're satisfied with like in the image below, input your game NFT ID and click on the submit button from the game's page
As can be seen in the image above, once we got the best score we could get before the end of the 30 minutes we purchased, we entered our game NFT ID of 2 into the appropriate field on the game page and submitted it. We can keep playing until the 30 minutes expire and if we are able to get a better score we submit it as well to replace the previous one.
You can figure out when your minutes expire by entering your game NFT ID in the form below on your game page. In our example below, we purchased our minutes at 19:12 (7:12 PM) so our minutes will end at 19:42 (7:42 PM); meaning we can try until that time to get a better score submitting each score every time to be safe.
After our minutes expire, we can wait for the right moment to process our score or we can process it straight away. Game contracts build up their prize pot with tokens collected from minute purchases and computes users' winnings based on their score.
For our current scenario, our game's prize pot is 3 USD which you can view from the game's page
Let's suppose we had a prize pot of 1000 USD and that the total addition of scores obtained in the game by users is 8000. We've gotten a score of 800 from playing our game so our winnings will be computed as such: 1000 * 800 / 8000 = 100 USD
If we had claimed our winnings when the total scores obtained in the game was 5000 and the prize pot at 800 for instance, we would have had claimed: 800 * 800 / 5000 = 128
So deciding when to claim your winnings is a strategic decision to make, you want to spot the moment when the total score obtained in the game is not too high but the prize pot is high. The total score is available at the top of the game page like in the image above (on the fifth line).
How To Claim Your Winnings
Go to the Games page and find your game
Go to your game's control panel menu and click on the Process Score button. You cannot fill in the form; you just need to validate the transaction in order to write the score obtained in the game previously in the gaming contract. PaySwap will query your score from the game's API and fill in the form so you can validate it.
You should be able to see the total score of the game updated with your score. The next step is to click on the Claim Rewards button in the control panel's menu. Validate the transaction to claim your rewards and transfer your earnings into your wallet. You can either claim your rewards straight away or wait a bit for the prize pot to get bigger with more players joining the game and buying minutes. The bigger the prize pot, the more you can win but this is a bit tricky since if the new players are able to raise the average score of the game, that might reduce your share of the total earnings. You basically have to pick the right time to claim your rewards, will you claim a bigger share of a smaller pot or a smaller share of a bigger pot?
How To Turn Every Game Into A Play To Earn Game
Add a form on the game site to enable users to update their scores. In the example image below, users can input their game token ID and click on the Save Score button whenever they have a score they are satisfied with and the game will register their score (saved under the name score) as well as the time of registration of the score (saved under the name deadline) and the time the user started playing the game (saved under the name startime) on the Firebase database (you can use any database you want). Make sure your games keeps track of the moment your users start playing their games (startime) as this parameter is extremely important to make sure users can only register scores for game minutes they've purchased. Without it, a user can spend hours maximizing his/her score for a certain game, then just buy 1 minute from the games' page on PaySwap and use that to register the score. With a startime parameter, we would be able to detect the discrepancy between the minutes purchased and the actual minutes played.
Deploy the game contract following the steps above and make sure you update the game information with an API link that will return your users' scores and deadlines
For our Mario game, our API link is: https://firestore.googleapis.com/v1/projects/tiktok-a2bdb/databases/(default)/documents/c4/
This is what we will be updating our game with. To fetch the score and a deadline of token ID #1 for instance, PaySwap will just pad the token ID #1 to the API link that we've registered which will give this https://firestore.googleapis.com/v1/projects/tiktok-a2bdb/databases/(default)/documents/c4/1 PaySwap is just padding the user's token ID to your API link so make sure that your saved API link has a trailing slash (/) Querying this endpoint returns the score and deadline that has been registered for the token ID 1 by its owner in the following format. Make sure the startime & deadline parameters are saved in seconds and not milliseconds
As long as your API follows the format above and returns an object with the format above, the system should have no problem updating your users' score information on the blockchain which is a necessary step for them to earn rewards.
Congratulations, your game now has a Play-to-earn component to it!!! Your users can now:
see your game from the games page
buy enough minutes in it for them to do their best scores
update their scores to your centralized database
use the PaySwap platform to report that score to the blockchain through an API that you've provided
claim their earnings if their scores are high enough
Last updated