3

I am currently working on P2E game. The game development is being underway in Unreal Engine 4. The users will play the game. And will achieve few tokens on behalf of their winnings. Let’s say I have a DAO P2E ERC20 Token named “Gold”. Each players Wining tokens are being save at the backend ( Database sql) along with the players addresses.

In general, Player will play the game, Win the match, The winning number of tokens along with the player address will be saved at the backend.

The problem I am facing right now, that How shall I create such a function that a user will simply Claim it’s tokens won from the match. I have created a contract and put some “Gold” tokens in that means I have formed a Pool from which the tokens will be transferred from Pool( contract) to user.

How a contract can verify that The person that is calling a function really have won x amount of $Gold tokens? How can I stop users that if they execute the functions directly from the etherscan so that It couldn’t be vulnerable to attack.

I have used several ways but it all kept failing. i have created API’s and fetched the data into the function of the particular user using Chainlink oracles that I got the problem that I can’t use msg.sender with the API link to get the particular player data.

I have tried Signature message still It doesn’t make sense that how could a contract would know that A person have actually won a particular amount.

Problem in a Nutshell:- I have ha P2E game, A user will play the game and will win ERC20 Tokens. The address and Amount will be saved in DB. Whenever player want to redeem the winning amount, it will simply click the button on the web page to redeem it’s winning. How can I transfer tokens from contract to User by validating that user have actually won x amount.

2 Answers 2

1

You mentioned you tried Chainlink APIs - that should be possible. Not sure where exactly your problem was in sending msg.sender but it should be solvable.

Another option would be to have a program that will call your smart contract based on the DB. So the user would press a button on your website, and that button (from your server) would issue a command to the earnings smart contract from a privileged address to send the user his funds. (or just update the earnings in the contract).

1

A common approach to this problem is to have a backend service that will track each user state.

When the user want's to mint its reward, the frontend send a request to the backend that will validate the state and provide a signed message.

The frontend sends to the contract the signed message as a transaction.

The contract verifies the signature and mints the tokens that were authorized in the message.

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.