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.

1 Like

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?


I’m really interesting abou your question because it’s the same that I have.

  1. Deposit (cashin): User should buy the token using a exchange like poocoin and send the tokens to contracts wallet (wallet that belongs to the owner and minted the tokens). I think this is the same process when you sell a box into the game. In this case the user pay the gas during the transaction.

  2. Withdraw (cashout): I see 4 options:

2.1) the contract wallet pays all the taxes
2.2) user pay the taxes and in this case I dont know how to implement this one
2.3) I don’t know what strategy cryptocity games like cryptoplane uses. When you withdraw there’s no prompt to user pay tax. Maybe they apply a tax fee (2%) of withdraw tokens in order to pay all gas fee.
2.4) Oracle I don’t know how it could help. As I know, oracle is used to get data from outside blockchain. I don´t know how it could help with transactions.

We can discuss more! Have you found awnsers?