0

I'm working in a online game project, Where users will deposit ETH into their account for playing game.

My problem is, Once a user deposit some ETH into his wallet. Example 0.10 ETH

So how we can track this balance and update user balance into our database, And allow user to play game. So while playing game user's balance will deduct or increase from our database balance not from directly their ETH wallet built into our website.

So how is it possible to track users deposit only once, So same deposit amount can not be grabbed by our code?

How peoples do this kind of stuff?

  • These things are easily managed by creating a contract and using a token to track individual balances of users. – Ayushya Mar 19 '18 at 10:30
  • i think you did not understand my questionn, – shawn Mar 19 '18 at 10:37
  • Oh okay. I get it now. So you can check balance of a user at specific block. That way you can prevent grabbing same value again. – Ayushya Mar 19 '18 at 11:10
  • So do i need to check balance into each block for each user? Suppose we have 10000 users then? – shawn Mar 19 '18 at 11:14
  • eth_getBalance takes a block argument. You can check balance of a user at a particular block. When they deposit balance, note down the block number too. – Ayushya Mar 19 '18 at 11:17
0

I understand your question like this. You have a website that allows users to play the games (offcourse they need balance to play). See if the below approach suits you.

  1. Allow them to make payment inside your site via metamask. You would receive the txnhash for it. You can then provide a button for the user to click the txnStatus in which you can find the txnStatus and update the user balance in your DB accordingly. Or, you can do a backend timer to checkup to see the txnStatus and update accordingly.
  2. Since, its within your website, you can reduce their balances on the backend, once they reach 0, you can block them out.
  3. If their balance is increased, provide a withdraw button in which update your db balance, and let the button click execute the contract method via metamask.
  • I'm not sure how contract works and how it will work for game website and manage balances. What i want is to provide website users just a deposit address, And when users deposit ETH to their address this deposit is credited to website owner's wallet. And user's balance is updated into the website database and users can play game now. And yes there will be withdrawal button too. This way deposit will actually go to website admin and if website users view their address balance in etherscan they there they should see $0 / 0 ETH. I think this is possible with hosted wallet, but i don't know how? – shawn Mar 20 '18 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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