<aside> 💡 In this article we’ll cover:

  1. What is a Remote Procedure Call (RPC)
  2. How to interact with Cosmos RPC using REST

</aside>

What is a Remote Procedure Call (RPC)?

A Remote Procedure Call (RPC) is a protocol that manages communication between two functions stored in different address spaces. The addresses can be on the same computer, but more often, RPCs are used to call functions on other computers using a client-server model.

The client makes a call using a stub that identifies the function, the parameters that will be used to call the function on the server side, and prepares the data to be transmitted in a process known as marshalling. RPCs utilize an Interface Definition Language (IDL) to translate calls and responses between clients and servers in several programming languages. Once the server receives the call, with the help of the IDL it routes the packet to the appropriate server stub, unpacks the data, and executes the function. The result of the function is returned to the client with the same process of marshalling and unmarshalling the data.

operating-system-remote-call-procedure-working.png

RPCs call functions in different address spaces as if they were in the same space which allows computers to communicate over a network without having many details of the network and while hiding the complexity of the communication from the user. The most common use for RPCs is to build Application Programming Interfaces (APIs).

Why would anyone want to do that?

RPCs are useful when one computer wants to call functions in several machines, several machines want to call a function on one computer, or complex computations are better suited for the server side rather than the client side.

One of the earliest use cases for RPCs was printers in corporations. It would be inefficient for each computer to have its own printer and an office with dozens of employees could not share one computer to create and store all of the documents they wanted to print. Offices needed a system for several employees to share their files with one machine that would handle all of their prints. RPCs were used to manage the calls from each of the worker’s computers to the printer.

https://giphy.com/embed/BeYzLDJhmKGFvDhePG

Today RPCs are used for cloud computing, communicating with databases, peer-to-peer networks, and most recently, Blockchains.

Blockchains are distributed networks of computers coordinating to reach a consensus on the state of all accounts and balances in the network. RPCs allow Decentralized Applications (Dapps), wallets, and remote programs to communicate with nodes participating in a blockchain. Researchers can query data from the network and developers can create peer-to-peer applications without having to run a node. Users write calls, and the network handles the rest.

Blockchains were innovative but struggle to scale and are siloed. In place of a one size fits all solution, blockchains have sprung up to specialize in different types of transactions. There’s a chain to store value, chains for currencies, chains for smart contracts, chains for games, and chains for supply chains. The fragmentation of data necessitated a way for blockchains to communicate with each other and Cosmos emerged as a way to connect chains to form The Internet of Blockchains.

Next, we’ll take a look at how Cosmos uses RPCs to communicate between chains, and how we can use Cosmos RPC endpoints to interact with the ecosystem.

Cosmos RPCs

Cosmos nodes can be accessed through three main endpoints.

  1. gRPC an open source Remote Procedure Call developed by Google. gRPC supports several languages but cannot be used for web applications.
  2. REST utilizes the gRPC-gateway which converts REST calls to gRPC calls.
  3. Tendermint RPC an RPC independent of the Cosmos SDK.