Is it possible to learn Solidity and create a game that uses it in three weeks of evenings and weekends? Unfortunately, I didn’t quite get the whole contract + web app + real world game tied together in time but I wanted to post my code as a check in and tell you all about the plan in order to keep myself honest.
Hermit’s Tome is the search for the lost spellbooks of a long forgotten wizard. It’s meant to play like Pokemon Go meets National Treasure, where puzzles lead the player to rewards placed in real life. Each spellbook reward is tied to an ERC721 Non Fungible Token, aka one of a kind collectible reward.
It was fun to learn the cold, hard logic of Solidity. The famed CryptoZombies tutorial lived up to its rep. I’m amazed by how much time and effort could be put into designing and optimizing for the Ethereum Virtual Machine. It’s a bit frustrating to manage a super deep tool stack, from local VM (Ganache) through to Web 3 enabled browser (MetaMask). There’s a minor thrill in deploying code to the EVM test net (Rinkeby) knowing that once it’s out there it can never change.
My contract (current draft) can be found here. I’m curious to hear from more experienced Solidity coders how it could be improved.
The core idea of the game is that players should be able to find a pass phrase (or “spell word”) either on a physical reward (spell book) or discover the spell word through solving a cryptographic puzzle, then enter that spell word into the Hermit’s Tome site to claim the NFT Spellbook for the corresponding digital prize. Each Spellbook is also described by its “powers”, which is a compressed way to store color, level, quest, and miscellaneous data while also being a unique ID.
In order to allow this, I built a “dead drop” mechanism into the token contract. I’ll mint tokens in advance and encode them with a hashed pass phrase. Then, anyone who can present the appropriate token powers (unique ID+) and spell words will be able to claim that token. The match is confirmed by comparing a keccak256 hash of the user’s input against the stored hash of the spell I’d previously enchanted the token with.
Why did I build this on the blockchain? Scarcity! This is one of the most exciting aspects of blockchain and what draws me to Ethereum (with its smart contracts) in particular. I can put a quest into the big wide world, and have an automated fair “judge” in place to accept only correct answers and deliver only an exact number of prizes.
One of the quirks of the EVM is that it does have a couple of local storage mechanisms but nothing (so far as I know) by way of a traditional table store. The most common solution to this seems to be to create many mappings (key => value stores). In the future, I’m curious to explore correlations between gas cost and number of mappings; I never generated enough token to observe a noticeable cost / performance increase. I’ll also be exploring alternatives to mappings, for example, a lot of white papers talk about storing data in merkle trees which does seem efficient but may not allow me the kind of random access to data that I need… yet another direction to take my questioning.
And that’s ultimately one of the greatest joys of working in this space: there is unexplored horizon in every direction. As an explorer at heart, I get inspired by the vast frontier.
I intend to finish Hermit’s Tome. In the future, I could see it being a sort of real life RPG where discovered spellbooks unlock future quests or serve as a helper text to quests in general. I had materials to create 50 physical spell books, which satisfies the artist in me, and I want to make them feel like an exciting reward. It does seem like launching around an event would make the most sense, so perhaps I’ll target Eth Denver…