Pixel Wizards: Token Dueling
It has been done… I present to you: Pixel Wizards: Token Dueling. A wizard dueling game to conquer the position of “Who is the wisest of ’em all?”. Do you have the skills to wager your $stars versus another wizard? Than this is a game for you. Choose your Pixel Wizard, use his wisdom and defeat your opponents!
Pixel Wizards token dueling is a game to play for fun but also to show the power of SVG based NFTs. In this article I, Headmaster Berny, will guide you through the game and it’s lovely pixel art retro interface.
Goal of the game
Each Pixel Wizard has a particular interest in a crypto token. He can use this wisdom to tell you the current price of that token. Within the token dueling game you extend on that knowledge and predict that your wizard’s token price will outperform your opponent’s.
Who is the wisest of ’em all?
Example
You have a Wizard that knows the price of $STARS. You create a duel and determine versus which token you want to duel, in this case $BTC. You select the amount of $stars you want to wager and finally the duration of the duel. The magic match maker finds you an opponent and start the duel.
During the duel the change percentage of both $STARS and $BTC are monitored based on the price when the duel started. This change percentage is displayed during the match so can you keep track wether you are winning or losing.
The duel ends when the chosen duration has passed. $STARS changed +0.25% in the past 10 minutes and $BTC changed -0.15%. This means that $STARS has outperformed $BTC and the $STARS wizard won the duel. The wizard will collect the wager and sent it to your wallet.
How to play the game?
In the previous example I’ve provided a textual example on how the game works. The game itself is played through a pixel art retro user-interface with a simple and straightforward layout. Let’s guide you through the different pages and setup your first duel!
Connect & start
In order to play the token dueling game you would want to have a Keplr Wallet and the Keplr extension installed. The game is currently only available on desktop.
You would also want to own one or more Pixel Wizards that can you buy from the Stargaze NFT Marketplace. Make sure you own a wizard with a token you want to wager with. Because each wizard you own can be played in the game. Fun fact: because the wizards are SVG files we can import them from your wallet into the game and have them animated in the UI.
Create a duel
In order to create a duel you would want to select a wizard with the token you want. Let’s continue on the example and select a $STARS wizard. After selecting the wizard you will setup the duel rules like opponent, wager amount and duration. Then just press “Duel!” and let the matchmaker find an opponent for you!
If for some reason the matchmaker cannot find you a opponent, the wizard will be removed from the queue after 10 minutes.
Find a duel
It sometimes can take a while to find an opponent because they need to match on all the criteria. Therefore we have created a page to show wizards who a ready to duel you. If you have a matching wizard with the right token, than you can instantly take the duel!
Both wizards are now matched against each other and dueling it out on who has chosen the best token to outperform the other.
Dueling
In the image below we will show you how both sides see their point of view. Notice the text in the bottom right corner displaying wether you are winning or losing!
Winner / Loser (Under construction)
Wether you won or lose the wager is not being displayed YET. This requires indexing the wagers that are omitted on the blockchain. It is something that we are looking into, but it should not break the fun of launching the game anytime soon. Make sure to monitor your wallet balance for the time being.
Spectate a match
If you don’t own a wizard or just want to watch ongoing duels then we got spectating mode available for you! Simply go to the “current duels” tab and spectate a match.
The technical side of things
On this simplistic user-interface, there are a lot of things happening in the background. As the wager is being held on-chain, it requires our contract to be queried and to resolve
Cw-wager Contract
The Cw-wager contract is a custom contract developed for this specific game. It matches owners of Pixel Wizards NFTs looking to make a bet on which of two assets will surge the most in price (by percentage points) in a specified amount of time.
Both wizards must have bet the same amount (available in increments determined at instantiation). The winner of the wager gains all of the funds deposited, minus a 10% percentage for service fees and fair burn, both of which are set at instantiation.
The $STARS wizard owner submitted their intentions to start a wager to the contract, which matches them immediately if another party’s submission matches their specific conditions. If none are available, the $stars wizard is added to the matchmaking pool, and their wager will be started when a suitable opponent is found.
Querying the contract:
- Wagers { } returns all currently running wagers
- Wager { token: (Addr, u64) } returns a wager the specified token is involved in
- TokenStatus { token: (Addr, u64) } returns if a token is in a wager or the matchmaking pool
- Config { } returns the current configuration of the contract
Cosmjs Agent
There is a cosmjs agent in play that does all the magic (querying), it’s the direct connection between the wizard game and the contract. This cosmjs agent will determine the winner of the wager based on data made publicly available by our Pixel Wizards Knowledge API. This knowledge API is updated every 2 minutes with data from Coingecko.
Helpful links
🪄 https://github.com/pixelwizardsnft/cw-wager
🪄 https://github.com/pixelwizardsnft/cw-wager-app
🪄 https://github.com/pixelwizardsnft/cw-wager-agent