Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: grondilu on November 15, 2010, 06:08:27 PM



Title: CGI script for donations
Post by: grondilu on November 15, 2010, 06:08:27 PM

I know that one of the good things whith bitcoins, is that you don't need a complex code into your website in order to accept donations.  Basically all you need is to display a bitcoin address.

However, I wonder if using a single fixed unique address is a good idea.  Because it could allow anyone, including the tax-humgry government, to know exactly how many bitcoins you have received.

I'm not concerned about this, because I don't maintain any website.  But I might be in the future.  Therefore I'd like to suggest to publish a small CGI script that would create a new bitcoin-address for every visitor who would like to make donation.

I suck a CGI programming, but at least I know that any programming language can be used to do that.  So I guess a simple "bitcoind getnewaddress SOMELABEL" could be used, where SOMELABEL would be any string the donator would like to enter.

I'd appreciate if someone could post an example of such a script.


Title: Re: CGI script for donations
Post by: teknohog on November 15, 2010, 09:07:24 PM
Code:
#!/usr/bin/env python

print("""Content-type: text/html

<html>
<body><pre>""")

# module installed via svn from http://json-rpc.org/wiki/python-json-rpc
from jsonrpc import ServiceProxy

from os import uname

hostname = uname()[1]

s = ServiceProxy("http://user:password@127.0.0.1:8332/")

label = "web donations on " + hostname

address = s.getnewaddress(label)

print(address + "\n")

donated = s.getreceivedbylabel(label)
if donated > 0:
    print("Donations so far: BTC " + str(donated))
print("Thank you for your support :)")

print("</pre></body></html>")


Title: Re: CGI script for donations
Post by: grondilu on November 16, 2010, 02:25:30 AM
Thanks !
I'm sure some people will find this useful.


Title: Re: CGI script for donations
Post by: jgarzik on December 12, 2010, 09:38:00 PM
You don't want to generate a new address for each web page hit.  That's a lot of useless addresses stored in your wallet.


Title: Re: CGI script for donations
Post by: BioMike on December 12, 2010, 09:41:12 PM
MyBitcoin seems to generate a new address for each payment when using the Bitcoin client (as in not through a MyBitcoin account). Just put a button for that on your site.


Title: Re: CGI script for donations
Post by: Gavin Andresen on December 12, 2010, 09:44:43 PM
You don't want to generate a new address for each web page hit.  That's a lot of useless addresses stored in your wallet.
Change "getnewaddress(label)"  to "getaccountaddress(label)" and you'll get the same address over and over, until somebody donates.  Then you'll get a different one.