2

Can someone please explain these concepts in a simplified manner and highlight their key distinctions? I would greatly appreciate any help in clarifying these concepts.

I'm relatively new to Substrate and I'm finding it challenging to grasp the concepts of runtime calls, RPC calls, and extrinsics. I've been reading the Substrate documentation, but I still have some confusion regarding these terms and their differences.

From what I understand, runtime calls are functions or methods defined within the runtime of a Substrate-based blockchain. They play a crucial role in executing the blockchain's functionalities and interacting with its state. However, I'm unsure about how they differ from RPC calls and extrinsics.

Extrinsics, as far as I know, are transactions or actions submitted to the blockchain by users or external entities. They package runtime calls along with additional information such as the sender's account, signature, and other transaction-specific details. When included in a block, these extrinsics trigger the execution of their associated runtime calls, resulting in modifications to the blockchain's state.

On the other hand, I've come across the term RPC calls, which appear to be a way for external entities (clients, services, etc.) to interact with a Substrate-based blockchain. From what I gather, RPC calls enable querying or invoking specific functionalities of the blockchain without necessarily submitting a full extrinsic. I believe they are primarily used for off-chain interactions and retrieving on-chain data.

I would greatly appreciate it if someone could provide a simplified explanation of these concepts and help me understand their key differences. How do runtime calls, RPC calls, and extrinsics relate to each other? When should I use one over the other? Clearing up these concepts would greatly enhance my understanding of Substrate. Thank you in advance for any assistance you can provide!

enter image description here

1 Answer 1

5

A blockchain is basically a database whose current state depends entirely on the data within the blocks. Each block contains a bunch of transactions*, and so the only way for a user to update the database state is by submitting a transaction.

So what is a transaction? A transaction basically represents a function call which has some effect on the state of the database. If I submit a transaction which says "transfer 10 tokens to Alice" which is then included in a block, then the state of the database at that block will reflect the fact that Alice has 10 more tokens and I have 10 less.

But which function calls/transactions can you make? Well, Substrate has this notion of "pallets". Each pallet basically defines a set of transactions (function calls) that it can execute, as well as some storage that may be modified as a result of executing the transactions. Ultimately, a Substrate based blockchain is just made from nodes that run some set of pallets which provide functions like "balances.transfer(to, amount)" and storage like "user Alice has balance 10,000". You can submit transactions, and query storage (among other things).

Ok, so how do you query storage or submit a transaction? Well, much like most Web2 services, Substrate based nodes (or light clients) expose a web API to allow users to interact with them. This API is exposed via HTTP and WebSockets, and uses a protocol called JSON-RPC (basically, you can submit JSON requests to the node which contain a method name and some parameters, and get back responses). Sometimes we just call this the RPC API. There exists an RPC method to allow people to submit transactions to a node, and another which allows people to query for the current state of some storage entries in a node, among other things.

But what about runtime calls? Well, pallets provide some flexibility in defining which transactions/storage a node can understand/provide. These pallets are all compiled to a WASM runtime which the node will execute, and the really cool thing about this is that the WASM which the node will execute can be upgraded (by submitting a transaction!) to alter/extend the behaviour of the chain without requiring node operators to update their binaries. Well, runtime calls are also compiled into this WASM runtime, and provide an API for you to call into this runtime to ask various things. When the runtime is updated, the runtime API's might also change.

Runtime calls vs RPC calls?? So, the JSON-RPC API provides a way to submit transactions, ask for storage values, call into runtime APIs and a bunch of other stuff. It is baked into the node binary, and is the same regardless of which pallets/runtime a node is running. Runtime API calls are upgradable, depend on the specific WASM runtime that the node is currently running, and can be queried via an RPC call.

* actually "extrinsics", which are either "transactions" (things submitted by users) or "inherents" (things added by the node itself).

Your Answer

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

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