2

I think library like BitcoinJ or python-bitcoin does the same (rpc call in the background). If that is true is there any reason behind using such libries in place of rpc call
For example:

(in case of python)

rpccall:

import requests
payload = {"jsonrpc":1,"id":"curltext","method":"getblockchaininfo","params"=[]}
response = requests.get(url,  data=json.dumps(payload))

Library call:

import bitcoinrpc
conn = bitcoinrpc.connect_to_local()
info = conn.getblockchaininfo()

Why should i choose one approach over the other when they are working the same way? What is the diffrence in between them? And which approach executes faster?

  • Which library? Which node software? – Pieter Wuille Jun 20 '18 at 20:44
  • Most libraries just call the RPC underneath. – Raghav Sood Jun 20 '18 at 20:59
2

I think library like BitcoinJ or python-bitcoin does the same (rpc call in the background)

No, they do not.

BitcoinJ is an implementation of a Bitcoin client. It connects directly to the Bitcoin network and speaks the Bitcoin Peer-to-Peer protocol. It does not call RPCs for a node.

f that is true is there any reason behind using such libries in place of rpc call

Libraries that do use the RPCs in the background allow you to abstact away the need to understand how the JSON-RPC protocol works. You don't need to have something that can send HTTP requests; you don't need to have something that can compute the basic authorization stuff; you don't need to have a JSON parser. Those libraries abstract those things away so that you can just deal with the RPC commands and the data they return.

There are no performance benefits. The only benefits are that the code is cleaner, easier to read, and easier to write.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.