Since we launched on Polygon a few weeks ago, we have seen a ton of quests being completed, items being earned and leaderboards being torn apart.
Unfortunately, we have also experienced some drawbacks of doing everything completely on chain. Lately, we have seen issues like failed or stuck transactions, as well as fluctuating GWEI fees, forcing people to postpone their much needed questing “fix” for the day.
Therefore, our current focus at the moment is to move a part of our app off-chain and keep the other part on-chain.
This is what we call the “hybrid” version of Knights & Peasants.
This article will shed some light on:
• What is staying onchain and what is going offchain
• Login and account creation
Trying to keep it as short and simple as I can.
Onchain versus offchain
Originally we wanted to migrate the entire app to a hybrid system but we soon realized that the app features can not be put under one group and thus the process of syncing and serializing data becomes more complicated.
For example: having the item vendor, crafting & upgrading offchain would mean additional write-ins to different smart contracts which in turn would force the players to sync the data more often to avoid huge sync costs and lots of new reworks.
So, we decideded to focus on building the web2 < → web3 infrastructure (server, “bridge” etc.) and migrate the quest system first. The Quest system is what makes up for the majority of transactions and TX fees, so this part is crucial to have offchain for the obvious benefits of eliminated gas fees and instant “transactions”. Other features offchain will be Knight and Peasant cooldowns, equipment durability and quest rerolls. Those make up for the bulk of transactions and will have the most impact being offchain.
Login and account creation
The server will use a simple database which will store a user’s progress every time he interacts with the application, in our case the quest system. For example, if you choose to reroll a new set of quests, the server will store your actions in the database together with the new information about the rolled quests. The same thing happens when you complete a quest; the server will compute your rewards (with the same % and mechanics as before) and they will be added to the database, bound to your user.
There will be no need for additional account creation. You will be prompted to sign a metamask verification signature and after the server validates it you will be considered “logged in”.
When playing with a web2 database there is a huge concern about security and data persistence, so in order to avoid any problems we will split the database between several servers and take daily snapshots.
Regarding security: there will be no user sensitive data stored on our servers. No emails, personal keys, nothing.
Another step in preventing some of the problems above is data retention. We consider that after a successful sync to the blockchain there is no need for the said data to still be in our servers (we will keep a simplified log of last 500+ actions for admin stuff). We’ll likely force at least 1 or more daily syncs to the blockchain in order to significantly lower the risk of corrupted data & loss of data.
How do you get to use your assets in-game? Or withdraw your rewards?
The good news is that your Knights and Peasants NFTs will be usable while in your wallet, but the items (you want to use on quests) need to be transferred to the game contract.
You’ll be able to batch send multiple items to the game contract in one transaction to make the job a little easier. The game contract will keep track of your assets and any items used on quests will be burned upon syncing.
Quest rewards will be minted to your wallet by the game contract when you decide to sync the data.
Benefits of a Hybrid system
The biggest and foremost benefit is that this will GREATLY improve user experience for our App. Say goodbye to signing a metamask transaction for every little thing, not being able to quest due to poor RPC connection or paying lots of gas fees.
Say hello to instant and costless transactions, whenever you want.
Another major benefit is that we are no longer bound by the strict rules of solidity and can therefore expand the game mechanics in many interesting directions such as: Peasant Skills, Equipment Set Bonuses, Idle Questing, Batch Questing etc.
We’ve been hard at working nailing down the server and the first phase is almost over. We have a fully functional server which can store user actions and is also able to sync user data & mint the rewards.
The next step will be creating and simulating the game mechanics on the server, improving the quest system (more info next week) and then finally connecting all the pieces together so testing can begin.
Since Peasant upgrading and Crafting will likely stay onchain for now, we are going to release those features before the Hybrid is finished. This means that we’ll likely see these features in the short term and we’ll keep you updated on our progress working on them!