The Bridge Connecting Web3 Applications and Chains

BeginnerSep 28, 2023
Why must we fill in RPC when adding a network on MetaMask? Why can't any Dapp development go without RPC? How can some leverage RPC for front-running trades? Which providers offer RPC services? This article answers all your questions about RPC.
The Bridge Connecting Web3 Applications and Chains

What is RPC?

Many people encounter the term RPC when manually adding a network RPC in wallets like MetaMask. However, RPC is an indispensable foundational technology for blockchain applications such as Dapps, Wallets, and CEXs. RPC stands for “Remote Procedure Call.” In Web2, RPC is a communication technique that allows one computer to call and execute a program on another. Through RPC, the caller only needs to pass the service name and parameters to communicate, a broad concept. In the blockchain context, RPC is the protocol that allows clients to interact with the blockchain. Users can query blockchain-related information (such as block height, block details, and node connections) and send transactions through the RPC interface.

Metamask Network Additions page (Source: Metamask)

Technical Principles of RPC

It’s vital to understand the three primary roles of RPC:

  1. Service Provider (RPC Server): Located on the server side, it offers both service interface definitions and service implementations. In the blockchain realm, this provider is akin to a node in the blockchain network, responsible for functionalities like storing and verifying transactions.
  2. Service Consumer (RPC Client): This operates on the client side. It calls remote services through a remote proxy object. In the blockchain, the registry functions like a node management system, noting which nodes offer specific services, and enabling other nodes to find and utilize these services.
  3. Registry: Also server-side, this registers local services as remote ones and manages them, making them available for the service consumer. In the blockchain scenario, service consumers resemble apps or users needing information on the blockchain. They request specific functionalities or data via RPC, similar to task requests within a team.

RPC call graph (source: Google)

The detailed technical architecture is shown in the figure above. To explain to you more clearly, we take the process of the project manager completing the report as an example to explain the detailed invocation process:

To elucidate using a simple analogy, imagine you’re a project manager needing a complex report. You might not be technically adept, so you enlist a data analyst. You:

  • Delegate: Write down the task requirements and relay them via a messenger to the data analyst. This mirrors how an RPC Client seeks a service but can’t execute it themselves.
  • Register: The messenger hands the task details to a coordinator who records and notifies the relevant analyst. The messenger acts like the Registry here.
  • Service: The analyst then takes on the task and analyzes data, akin to executing a remote function.
  • Execution: The analyst processes the data according to your specifications.
  • Record: Results are handed to the coordinator for documentation.
  • Feedback: The messenger returns the analyzed data, and you receive your complete report.

Why is RPC Necessary?

Given the decentralized and distributed nature of blockchains, data is stored across numerous nodes. Notably, to run a node and participate in block validation, computers need to meet specific hardware and software criteria. In networks like ETH and ADA, running nodes also demand staking a certain amount of tokens.

Not every node can use the RPC protocol. Typically, only computers running blockchain client software can act as RPC nodes. Most projects cannot bear the operational and maintenance costs of running nodes, given the immense time, manpower, and resources required. This gave rise to dedicated RPC nodes and service providers.

What are the Uses of RPC?

From the previous section, it’s evident that a vital function of RPC (Remote Procedure Call) is to establish a connection between terminal applications and the blockchain. Therefore, the primary use of RPC is, during the development process, to choose an appropriate RPC service provider to enable users to execute on-chain transactions and queries.

For the average Web3 user, the most direct use-case is to switch to an RPC gateway with lower latency during network congestion, thereby reducing their delay and speeding up transaction execution. In theory, RPC can be applied to any project that requires blockchain transactions or information queries.

Private RPC

The vast majority of blockchains offer free public RPCs for application testing. However, these come with rate limitations, leading to the emergence of private RPCs. A private RPC endpoint has a unique URL, and only its owner can use this URL to send transactions to the public memory pool, thus offering a direct connection to the node provider. The benefits of using private RPCs in practice include:

  • Faster transaction dispatching during exclusive, first-come-first-serve NFT minting periods
  • Sending transactions to take advantage of time-sensitive arbitrage opportunities
  • Rapidly claiming airdrops

RPC Operation Example

Regarding RPC usage in development, developers should refer to documentation. This article uses the RPC switch in wallets, like MetaMask, as an illustration: Go to settings, select the network, click on the network name you wish to change the RPC for, modify the RPC URL on the right, and save to finalize the change. Users should consider latency levels as switching to a high-latency RPC might slow transaction speeds.

MetaMask has an RPC change page (source: MetaMask web version).

When using it, it’s crucial to compare latency levels. If you switch to an RPC with higher latency, transaction speeds may slow down.

What is an RPC Service Provider?

Due to the complexity of setting up and operating nodes, there has emerged a category of businesses that specialize in operating these nodes to provide services such as RPC/API to projects. Projects can send requests to these providers via the Internet. These providers run fully synchronized, always-updated nodes available 24/7, rather than the projects sending requests to their local nodes. Many providers offer more than just RPC services; they also offer various related services like APIs, SDKs, etc. For developers and individual users, when choosing a provider, it’s essential to consider factors like transaction speed, cost, customer service, and the range of tools they offer.

RPC service providers also provide the private RPCs mentioned earlier. Most RPC providers cater to multi-chain operations and often offer free trial and public versions. Below are some popular RPC service providers:

Flashbots

Flashbots is a research-driven company focusing on Miner Extractable Value (MEV), aiming to mitigate the negative externalities and risks that MEV poses to smart contract blockchains. Their RPC service, Flashbots Protect, consists of both RPC and API. Developers can easily embed it into their applications using the API. Ordinary users can add its RPC to their wallets, directing their transactions to Flashbots. This process involves sending transactions directly to miners instead of the public pool, preventing the “sandwich attack” prevalent in MEV. Currently, Flashbots is a leading entity in the industry for MEV research.

Note: A sandwich attack refers to the tactic of completing a trade just before a user’s transaction gets confirmed, causing the price to rise, and then selling at a premium after the user’s transaction completes to make a profit.

Infura

Infura is an IaaS (Infrastructure as a Service) product designed to make accessing Ethereum data easier for developers and users. Acting as a full Ethereum node, it offers an API interface that allows DApps to be swiftly connected to the Ethereum platform for interaction without running a local Ethereum node. Its clientele includes Metamask, Uniswap, Compound, and more.

Alchemy

Alchemy provides SDKs and APIs for building multi-chain Web3 DApps, and educates users on using these tools through community and university-like initiatives. Alchemy has supported over $100 billion in on-chain transaction value, has over 10 million end users, and has generated over $1.5 billion in royalties. Notable clients include Opensea, GMX, and AAVE.

Ankr

Ankr offers various node services, including public and private nodes, supporting over 30 blockchains. Ankr also provides API interfaces based on RPC and WebSocket protocols, as well as several development tools and SDKs, such as Web3.js and Truffle, enabling developers to easily build and deploy blockchain applications. Their client base includes Binance, Sushiswap, Meta Apes, and more.

Quicknode

QuickNode provides API services to users directly through dedicated nodes. It supports various regions, multiple testnets, and archive nodes, offering developers enhanced blockchain access performance and greater stability. Features include an intuitive dashboard, analytics suite, and a remote procedure call writer, supporting over 20 chains. Clients include Nansen, Algofi, and Dapprader.

BlockPI

BlockPI is an RPC with a distributed network structure, a distributed multi-chain acceleration layer participating in the decentralized Web3 environment. In early 2023, it successfully upgraded its public RPC, offering a more stable and faster free RPC service. In theory, its architecture fundamentally addresses the congestion issue of RPC requests and boasts infinite scalability.

Conclusion

With the continuous maturation of blockchain technology and increasing adoption of Web3, RPC services, as one of the foundational services, hold a promising future. The demand from developers for RPC services is predictably going to rise. From an individual’s perspective, frequent traders who require faster transaction speeds could benefit greatly from selecting a lesser-used public RPC or investing in a private RPC, especially for activities like airdrops or NFT minting.

Tác giả: Wayne
Thông dịch viên: Piper
(Những) người đánh giá: Edward、KOWEI、Elisa、Ashley He、Joyce
* Đầu tư có rủi ro, phải thận trọng khi tham gia thị trường. Thông tin không nhằm mục đích và không cấu thành lời khuyên tài chính hay bất kỳ đề xuất nào khác thuộc bất kỳ hình thức nào được cung cấp hoặc xác nhận bởi Gate.io.
* Không được phép sao chép, truyền tải hoặc đạo nhái bài viết này mà không có sự cho phép của Gate.io. Vi phạm là hành vi vi phạm Luật Bản quyền và có thể phải chịu sự xử lý theo pháp luật.
Bắt đầu giao dịch
Đăng ký và giao dịch để nhận phần thưởng USDTEST trị giá
$100
$5500
Đăng ký ngay