<blockquote>
  <p>I think library like BitcoinJ or python-bitcoin does the same (rpc call in the background)</p>
</blockquote>

<p>No, they do not.</p>

<p>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.</p>

<blockquote>
  <p>f that is true is there any reason behind using such libries in place of rpc call</p>
</blockquote>

<p>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.</p>

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

CC BY-SA 4.0
2018-06-21T09:34:32.470Z
i found a answer by  @Pieter Wuille for similar question :  https://bitcoin.stackexchange.com/questions/49362/what-is-better-pre-existing-bitcoin-core-api-bindings-for-python-or-custom-wrap
 there he is saying it will have lower overhead using rpc call
Parishilan Rayamajhi
CC BY-SA 4.0
2018-06-20T22:50:58.327Z
2018-06-20T22:50:58.327Z
Ava Chow
<p>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<br>
For example:</p>

<p>(in case of python)</p>

<p><em>rpccall:</em></p>

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

<p><em>Library call:</em> </p>

<pre><code>import bitcoinrpc
conn = bitcoinrpc.connect_to_local()
info = conn.getblockchaininfo()
</code></pre>

<p>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?</p>

CC BY-SA 4.0
2018-06-20T20:44:12.720Z
Which library? Which node software?
Pieter Wuille
CC BY-SA 4.0
2018-06-20T20:59:58.343Z
Most libraries just call the RPC underneath.
Raghav Sood
<bitcoin-core><json-rpc><library>
Which approach is better to interract with Bitcoin node : Rpc call or Library?
Parishilan Rayamajhi
# Which approach is better to interract with Bitcoin node : Rpc call or Library?

(Asked by: username_0 on 2018-06-20)

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?

**Tags:** bitcoin-core, json-rpc, library

> **Comments:**
> **username_1**: Which library? Which node software?  
> **username_2**: Most libraries just call the RPC underneath.  

---

## 1 answers

### Answer by username_3 on 2018-06-20. Score: 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.

> **Comments:**
> **username_0**: i found a answer by  @username_1 for similar question :  https://bitcoin.stackexchange.com/questions/49362/what-is-better-pre-existing-bitcoin-core-api-bindings-for-python-or-custom-wrap  there he is saying it will have lower overhead using rpc call  

---

