What's needed to host a competitive game site Let's say I wanted to host a site in which


users create their own accounts
they deposit bitcoins in said accounts
a commission of, say, 0.05% is kept of all the bitcoins that are deposited in the site
users play a competitive game with each other (e.g. chess, or others for more players) for a bet
the winner gets the full bet
each user can withdraw their bitcoins any time they want


This, I figure, would be quite hard to get right due to all of the different aspects involved, such as user trust, security and technicalities.

My questions are:


How do current betting sites handle the deposits/withdrawals of bitcoins, and how do they keep a commission out of it?
Any small site could rely on trust and do this in a manual fashion, but I'd assume any professional site does not handle this manually. So, is there an existing library (I'll use Node.js, in case it matters) or third-party service for this? And should the bitcoins be stored in a conventional offline wallet(s)?
And last, is there a way to "prove" that the games are fair in order to establish trust? Are there any legal requirements regarding to this?
How do current betting sites handle the deposits/withdrawals of bitcoins, and how do they keep a comission out of it?


Just like any other payment: you track the blockchain and keep balances in your server database.


You can charge the commission on deposit (e.g. 0.5% fee, when depositing 10BTC just credit 9.95BTC)
You can charge per game (e.g. when each player bets 5BTC in a 2 player game = 10BTC, only pay the winner 4.95 from their rival) and keep 0.05 (0.5%).
In betting games you can also schew the long-term statistics against you so the house has an edge (just like casino roulettes have 0, and some even 00).



  Any small site could rely on trust and do this in a manual fashion, but I'd assume any professional site does not handle this manually. So, is there an existing library (I'll use Node.js, in case it matters) or third-party service for this? And should the bitcoins be stored in a conventional offline wallet(s)?


This would work just like any other business, just browse this site. You can rely on external businesses to do this for you, or create the system yourself (leveraging libraries or not, you must listen to the blockchain events and act accordingly).


  And last, is there a way to "prove" that the games are fair in order to establish trust?


If games are deterministic (like chess) the issue boils down to trust between users (is this guy going to cheat me using a chess engine?) since you couldn't influence the outcome anyways.

If games are based on chance, either the users must have faith in you or you have to provide a way for the user to verify you're not cheating him. How such a scheme could be implemented depends on the detailed mechanics of the game (you could even leverage Bitcoin's blockchain for this).


  Are there any legal requirements regarding to this?


Dealing with the legal system is the hard part here. Just like any other legal matter... it depends on your jurisdiction! In my country you have to be audited before running a betting business.