How to connect to Bitcoin or Ethereum with an RPC and how do Node API Providers differ?

Since more and more businesses depend on cross-platform services and applications, the need for APIs has grown exponentially in the last 15 years, particularly in disruptive technologies, including blockchain, Artificial Intelligence, and data analytics.

In this article, our focus is to explore the connectivity to the Bitcoin and Ethereum blockchain networks with RPCs and establish how you can outsource the node management to a third party to reduce your workload.

If you want to read more about RPCs and REST APIs in terms of differences and applications, check out our article: What is a Blockchain RPC Node API and How to Choose the Right RPC Provider?

Connecting to Bitcoin or Ethereum Network with RPC

It must be noted that to run bitcoind on versions below 0.3.14, you should call the HTTP JSON-RPC server, however, the basic authentication must be used while establishing the connection. In case your library or protocol demands the realm, use ‘jsonrpc‘.

If you are using Python, they have a dedicated implementation for JSON-RPCs, called python-jsonrpc, which automatically creates the native methods for API calls. But since it was designed for older versions of bitcoind, it is most likely to be inefficient for your present use cases. Therefore, jgarzik has produced a fork, known as Python-BitcoinRPC that is aimed at the latest versions, thus making it more secure and efficient at the same time.

Please use the following code snippet for installing your python-rpc of choice:

from jsonrpc import ServiceProxy // if you want to use python-jsonrpc
from bitcoinrpc.authproxy import AuthServiceProxy // if you want to use python-bitcoinrpc
access = ServiceProxy("http://user:password@127.0.0.1:8332")
access.getblockchaininfo()
access.listreceivedbyaddress(6)
#access.sendtoaddress("11yEmxiMso2RsFVfBcCa616npBvGgxiBX", 10)

The steps above give you an example of how to connect to the Bitcoin network and below you will find that the process is more or less the same for Ethereum.

To allow clients to connect to their network, Ethereum depends on JSON-RPC as well and allows a swift connection to sync up with main nodes. While you can rely on JavaScript (JS) libraries to serve the purpose, Ethereum itself provides an array of libraries to reduce your burden as you just have to write a single line of code to initialize RPC requests at a node without building the entire logic from scratch. For instance, Web3.js happens to be the most popular library these days and the following snippet shows how remote calls can be initialized:

Just for your reference, Anyblock Analytics offers a solution in this regard where you do not have to create and deploy Ethereum nodes from scratch. They provide a SaaS-based API service so you just have to connect with them via APIs and can then monitor their health as well. It is more like a node in the cloud!

Now that we have explored the process of establishing the connection with Bitcoin and Ethereum, let’s discuss the pros and cons of running a node yourself in contrast to outsourcing its operations to a third party.

The Potential Pains of Running a Self-Hosted RPC Node

Consumes Plenty of Time

Unreliable Synchronization and Missing Optimization

Additionally while building a scalable application, it is important to consider the importance of load balancing, which can be an entirely different domain if you do not know much about the cloud and networks.

Higher Cost

The Benefits of Outsourcing Node Management and Operations

Concisely, all of the disadvantages mentioned in the previous section are addressed by node infrastructure providers and they charge you a predictable subscription fee for their services.

At Anyblock Analytics, our clients have the liberty to select dedicated or shared nodes, as per your requirements. The following table summarizes the salient features of each service:

Dedicated node

  • Limited to private enterprises and consortium chains
  • More privacy
  • Clients need to commit to long-term contracts due to the operational costs
  • Developers can leverage the entire resource-set offered on our cloud

Shared node

  • Available for public networks in the cloud
  • Relatively less privacy depending on the jurisdiction (i.e. GDPR or Patriot Act)
  • Flexible contracts that are usually cheaper in the short run
  • Limited/shared resources

Selecting the Best API Node Provider

Technical Factors

Moreover, since blockchain networks are based on P2P architecture, the nodes must have low latency to ensure the communication is swift and there are minimal delays. To address this concern while using Node as a Service, you should select a provider that offers infrastructure close to your location, because when the physical distance increases, it usually takes more time to ping the node. You can also read this article to understand the factors resulting in higher pings.

Non-Technical Errors

Secondly, you should have a fair idea about their commercials. Some node providers prefer charging on demand and others have a flat fee. Therefore, you should consider your use cases before selecting a platform to ensure your business stays profitable in the long run when all costs add up.

Finally, pay attention to the support hours offered and the experience of the team, especially if you are looking to run a node for the first time and expect to need help during setup.

Conclusion

It is worth noticing that Anyblock Analytics provides JSON-RPC APIs that you can use to connect with either of these networks. Moreover, you can even outsource the entire DevOps work to reduce your bottleneck and save time for the development of your own product that you would otherwise spend in network configurations.

Freddy Zwanzger — Co-Founder of Anyblock

Interested or questions?

Follow us:
Twitter, LinkedIn,
Medium, YouTube

Originally published at https://www.anyblockanalytics.com on March 4, 2021.

Anyblock Analytics is a German blockchain solution provider. We offer consulting, tools and data to integrate business processes with blockchain.