Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
RPC batching example
import sys,os
# just grab the library from the closest bitcoin instance
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'bitcoin', 'qa', 'rpc-tests', 'python-bitcoinrpc'))
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
prox = AuthServiceProxy('http://user:pass@')
# list of addresses to import
addresses = [
batch = []
reqid = 0
for addr in addresses:
batch.append({'version': '1.1',
'method': 'importaddress',
'params': [addr, '', False],
'id': reqid})
reqid += 1
responses = prox._batch(batch)
for r in responses:
if r['error'] is not None:
print 'Request %i failed with error %i: %s' % (r['id'], r['error']['code'], r['error']['message'])
print 'Request %i succeeded: %s' % (r['id'], str(r['result']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.