I need some help to code an in-game currency for my game.
Explaining: I need to "swap" a token to an in-game currency (off-chain), and later transform the in-game currency into on-chain tokens. It's done in many games, like PvU (Plant vs Undead), Crypto Cars, etc. In Plant vs Undead you can covert PvU (on-chain token) to LE (the in-game currency), play the game, earn more LEs and them convert LE to PvE to cash out. How can this be done?
So my question can be broke into to questions:
- Cash in: deposit tokens to get the in-game currency
- Cash out: withdraw the in-game currency and give the players the game tokens
To cash-in I believe I can use solidity events, where the game contract gets the player token and emits an event that is consumed by my backend and adds the in-game currency in our database, but I am not sure it's the best solution.
To cash-out I have no idea, is there a way to do this without needing my backend to call the game contract and pay taxes for this? Maybe an Oracle? I am curious how these games that use these in-game currencies to avoid gas taxes in every transaction.
Any help will be very appreciated.