How to build server side wallets for web3 game developers.
I want players to be take items drops (not NFT regular items) to a merchant NPC. The merchant will take hand out a token.
There are a few ways to build a crypto game.
- All data is on chain. This includes all logic and items.
- Pros: Completely decentralized. Follows the web3 ethos.
- Cons: Very costly for the player. Every data update must be a transaction and will be slow.
2. Some data is on chain. This might be ERC-20s or NFTs. Numbers like score is on a game server.
- Pros: Can build more web2 friendly games (FPS, MMO, MOBA) with high throughput.
- Cons: Not completely decentralized.
The reality is most web3 games have both off-chain and on-chain data.
Because there are some off-chain and on-chain logic, we need a wallet that connects web2 to web3. One possible solution is to create a server side wallet.
Non NFT item drops are stored in a game server. This is your traditional way of storing data. When the a player interacts with an NPC, the player is telling the game server “I want my token”. The game server will verify if they’re eligible. If eligible, the server will communicate with the game wallet to send tokens to the player.
Creating the Wallet
Since there are many backend game servers written in different languages, the idea is to:
- Create a generic RESTful API layer. This allows any server to interact with it by using GET and POST requests.
- An authorization layer. Only servers with the
apiKeycan send tokens.
- EVM agnostic. Wallet can interact with multiple blockchains.
- Simple deployment (see below).
How to run a server side wallet locally.
How to deploy a server side wallet (free)
Many dapps today combine off-chain and on-chain data. This is also true for web3 games. It’s not be practical to store all game data on chain. Only store what is of value. The rest should have some server logic. And that server logic can interact with a server wallet.