Still trying to figure this out - I thought it was a routine thing?
I imagine most people doing this run a Bitcoin daemon on their server. But there's nothing wrong with your approach, just make sure to do something sensible when you run out of addresses!
Do you have Python available? Here's a script (that's not as simple as it could be): call it with the number of addresses you'd like to create, and it will print out each address. So redirect the output to a file by putting "> addresses.txt" after the call to the script on the command line.
#!/usr/bin/env python
# 2011-07-08 J.P. Larocque. Public domain.
RPC_URL = "http://127.0.0.1:8332/"
#RPC_PASSWORD = "topseekrit"
RPC_PASSWORD = None # Prompts if None.
import os, sys, json, random, getpass, base64, urllib2
def print_usage ():
print >>sys.stderr, ("Usage: %s NUM_ADDRS [ACCOUNT]" %
(os.path.basename (sys.argv[0]),))
def main (args):
if not (1 <= len (args) <= 2):
print_usage ()
return 2
try:
num_addrs = int (args[0])
if num_addrs < 0:
raise ValueError, "NUM_ADDRS must be a non-negative integer."
account = None if len (args) == 1 else args[1]
except ValueError, e:
print >>sys.stderr, e
print_usage ()
return 2
for i in xrange (num_addrs):
print getnewaddress (account)
def getnewaddress (account):
return bitcoin (["getnewaddress", "" if account is None else account])
_opener = urllib2.build_opener (urllib2.ProxyHandler ({}))
def bitcoin (args):
global RPC_PASSWORD
if RPC_PASSWORD is None:
RPC_PASSWORD = getpass.getpass ("RPC password: ")
return trivial_jsonrpc (RPC_URL, "", RPC_PASSWORD, _opener,
args[0], args[1:])
def trivial_jsonrpc (url, username, password, opener, method, params):
# Disclaimer: I don't know JSON-RPC, and I don't care to.
req = {"jsonrpc": "1.0",
"id": "%16X" % (random.randrange (2**64),),
"method": method,
"params": params}
urllib2_req = urllib2.Request (url, json.dumps (req))
urllib2_req.add_header ("Content-Type", "application/json")
urllib2_req.add_header ("Authorization",
"Basic " + base64.encodestring (username + ":" + password).replace ("\n", ""))
urllib2_resp = opener.open (urllib2_req)
resp = json.load (urllib2_resp)
assert req["id"] == resp["id"]
if resp["error"] is not None:
raise ValueError, resp["error"]
return resp["result"]
if __name__ == "__main__":
sys.exit (main (sys.argv[1:]))
To use this, you'll need to make sure that your copy of Bitcoin is listening for RPC connections. You can do this by editing a text file called "bitcoin.conf" (create it if it doesn't exist) in your Bitcoin data directory and add this:
rpcpassword=SECRET
Substituting a new, real password for SECRET. Restart Bitcoin for the change to take effect.
You can run the above Python script by saving it to a text file and running this from your command line:
python bitcoin-getnewaddresses.py 1000 > addresses.txt
RPC password: [not echoed]
If this works for you, feel free to send what you think this was worth my way: 1FMC9HqiEP6Xuk4WJhEZEYK36CqovxeVQy