4

I'm sorry. This might be a silly question but I am very much new to backends and networking protocols. I can write decent smart contracts but I don't know much about the backend.

So... I wanted to learn how I can build an API to get transaction results from transaction hashes. What I got stuck is the very first place... I happened to know that REST API, JSON RPC, RPC, SOAP, GraphQL all are network protocols. But since REST is so famous, why do Ethereum and Blockchain use JSON-RPC calls and not REST. I'd searched the internet for it but could find no distinct reason that can make me understand. Happened to get it that JSON RPC calls are direct and faster... I really am a beginner in this so can I get a simple analogy and a precise reason from this talented community please?

2 Answers 2

8

JSON-RPC is not a behaviour of the Ethereum network - Ethereum clients don't talk to each other via JSON-RPC - it's just a notation to encode a remote procedure call that some Ethereum client can interpret as commands sent by the users, and they can respond to those requests in a standard manner.

JSON-RPC is easy to implement, it's easy to read and to debug - it's just text in a JSON notation - and this is why is so widespread in many applications, not only in Blockchain clients.

REST is not meant to send commands at all but to manage resources, and in particular it allows HTTP to act as a sort of CRUD manager for web resources. With REST you can Create, Read, Update and Delete a resource managed by the server you are sending the REST request to.

The above features are usually not what Blockchain clients need to offer to their user. Blockchain clients usually need to expose commands to be called, and to respond with results. This is why usually JSON-RPC is a better option.

1
  • wow! Thanks for the elaborate answer... I think I got the gist of it somehow... :D Jul 25, 2020 at 16:39
2

Your question assumptions are false, because there are other API protocols like graphQL for Ethereum.

Why everyone is using JSON-RPC is because Satoshi chose JSON-RPC for Bitcoin back in 2009. Then everyone followed the suit. Not for a particular reason, but because of cargo culting and so on, though JSON-RPC has some good properties like being curlable and human readable.

1
  • Thanks for answering... hmm... that must be the case! I think I got it somehow! :) Jul 25, 2020 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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