# Sample account system using JSON-RPC needed

Post by: satoshi on July 16, 2010, 07:45:10 PM

We need someone to write sample code, preferably Python or Java, showing the recommended way to use the JSON-RPC interface to create an account system. &nbsp;Most sites that sell things will need something like this. &nbsp;Someone who's kept up on the JSON-RPC threads here should have some idea how it should work.

When a user is logged in to their account, you show the bitcoin address they can send to to add funds. &nbsp;Before showing it, you check if it's been used, if it has then you replace it with a new one (getnewaddress <username\>). &nbsp;You only need to keep the latest bitcoin address for the account in your database. &nbsp;(I posted a sample code fragment for this in an earlier thread somewhere, search on getnewaddress)

You use getreceivedbylabel <username\> with the username as the label to get the "credit" amount of the account. &nbsp;You need to keep a "debit" amount in your database. &nbsp;The current balance of the account is (credit - debit). &nbsp;When the user spends money, you increase debit.

If you're requiring more than 0 confirmations, it's nice if you show the current balance (0 confirmations) and the available balance (1 or more confirmations), so they can immediately see that their payment is acknowledged. &nbsp;Not all sites need to wait for confirmations, so the dual current & available should be optional. &nbsp;Most sites selling digital goods are fine to accept 0 confirmations.

A nice sample app for this would be a simple bank site, which would have the above, plus the option to send a payment to a bitcoin address. &nbsp;The sample code should be the simplest possible with the minimum extra stuff to make it a working site.

vekja.net is an example of a site like this.

---

Source file: bitcoin-forum-satoshi-nakamoto.tgz

External link: https://bitcointalk.org/index.php?topic=417.msg3579#msg3579
