I have a game where the data is saved in a MYSQL database

  1. Is it possible to create a "play to earn" game, that the balance is saved in the database and the user can make the withdraw using the metamask on the site?

  2. How will the smart contract know that that user has direct XX tokens?

1 Answer 1

  1. Yes it is possible. If you trust the information in your database you could allow users to connect their wallet to your game. You could then have a withdraw function that transfers the earnings to the users.

  2. The only way the smart contract could know what tokens the user has is by getting the data from your database. Collecting this off-chain data is typically done using a relayer or oracle. I would suggest checking out OpenZeppelin Defender for a relayer and Chainlink for an Oracle.

However instead of trying to run everything off-chain I would strongly consider looking into how you can move more on-chain without ruining the users experience. This would prevent users loosing all their earnings if your game ever disappeared before they clicked withdraw.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.