/
bitcoincli.py
executable file
·38 lines (30 loc) · 1.17 KB
/
bitcoincli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
""" Demonstrate the bitcoind JSON-RPC interface """
import sys
import socket
try:
from jsonrpc import ServiceProxy
except ImportError:
print """The demo expects the bitcoin-targeted version of thejsonrpc
package, from https://github.com/jgarzik/python-bitcoinrpc"""
sys.exit(0)
RPCUSER = "me" # rpcuser and pw are defined in ~/.bitcoind/bitcoin.conf
RPCPW = "mypassword" # see https://en.bitcoin.it/wiki/Running_Bitcoin
BTIP = "127.0.0.1" # by default, bitcoind only accepts localhost connections
BTPORT = "8332" # the default bitcoind port
BTURL = "http://%s:%s@%s:%s" % ( RPCUSER, RPCPW, BTIP, BTPORT )
PROXY = ServiceProxy(BTURL)
try:
BTINFO = PROXY.getinfo()
except socket.error:
print """Error connecting.
Make sure bitcoind is running on port %s, and is accessible""" % BTPORT
sys.exit(0)
except ValueError:
print """Do the rpcuser and rpcpassword parameters match bitcoind.conf?"""
sys.exit(0)
print "BitCoin stats"
for key in BTINFO.keys():
print " %s; %s" % ( key, BTINFO[key] )
print "See https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list"
print "for the full list of functions available"