Smart Contract and in-game (off-chain) currency

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:

  1. Cash in: deposit tokens to get the in-game currency
  2. 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.

Everything, what you are asking is done with an oracle and you listen to events

1 Like

Why use an Oracle, isn't cheaper make my server side feed this data?

that is called oracle

that your server executes a function of a smart contract, it is called oracle

I mean, Chainlink Oracle services/datafeeds... Is there any advantages?