What is an RPC node and how to build one as a developer.
Also, are there any resources available?
Remote Procedure Calls, or RPCs, are a way for an external program (eg. polkadot{.js} apps) to make calls to a Substrate node or another way of saying this is that RPC's is a way to allow the outside world to communicate with our blockchain.
When you run a Substrate node you can expose an HTTP or WebSocket RPC server via a TCP port. You can also specify whether you want to expose all RPC methods from your node or only those deemed as safe.
Substrate nodes use JSON-RPC which is defined as:
A stateless, lightweight remote procedure call protocol that is encoded in JSON. JSON-RPC provides a standard way to call functions on a remote system by using JavaScript Object Notation.
Substrate exposes metadata that is organized per pallet on your chain. This metadata is automatically generated by Substrate and available via RPC. This metadata reveals information about the storage items, extrinsic calls, events, constants, and errors available per pallet. This is how polkadot{.js} apps generates its api.
One of the most important RPCs is rpc_methods
. This RPC shows all the RPC methods that are available on that particular node.
You can call this RPC on the Polkadot network by running the following curl command in your terminal:
curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "rpc_methods"}' https://polkadot-rpc.dwellir.com
Another way is to this is by opening polkadot{.js} apps and poke around to see all the available RPC calls that are available on Polkadot.
If you want to learn more I recommend you follow this tutorial and when you successfully run your Substrate node, try running it with the following command: cargo run -- --help
and scroll up and see all the available RPC flags and options that are available to use.
So in essence when you're running a node:
./target/release/node-template \
--base-path /tmp/node01 \
--chain ./customSpecRaw.json \
--port 30333 \
--ws-port 9945 \
--rpc-port 9933 \
--telemetry-url "wss://telemetry.polkadot.io/submit/ 0" \
--validator \
--rpc-methods Unsafe \
--name Node01
As shown above, it is common to have a subset of your nodes run an RPC server so that the outside world can communicate with your blockchain. In this example, port 9933
is running an HTTP RPC server and port 9945
is running a WebSocket RPC server.
WebSockets are nice because you can subscribe to them and receive live push notifications when what you're subscribed to changes.
References & Resources