Skip to content

Commit

Permalink
Merge pull request #493 from MoralisWeb3/rpc-docs-revamp
Browse files Browse the repository at this point in the history
rpc-docs-section-revamp
  • Loading branch information
bharathbabu-moralis authored Sep 12, 2024
2 parents c2006ab + a6d17b4 commit 3c83579
Show file tree
Hide file tree
Showing 72 changed files with 2,266 additions and 84 deletions.
96 changes: 88 additions & 8 deletions docs/07-rpc-nodes/01-overview.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,99 @@
---
title: "RPC Nodes"
title: "Overview"
slug: "/rpc-nodes"
sidebar_label: "Overview"
sidebar_position: 0
sidebar_class_name: "sidebar-overview"
---

import NodeBanner from "@site/src/components/NodeBanner/NodeBanner.tsx";

To put it simply, RPC nodes are nodes (servers) that access a blockchain network (for example Ethereum), which enable you to interact with the network without running your own node.
# RPC Nodes Overview

## Overview
Welcome to the Moralis RPC Nodes documentation! This section will guide you through everything you need to know to effectively use Moralis RPC Nodes for accessing blockchain data across various supported networks. Our RPC nodes provide a powerful and reliable gateway for interacting with blockchain networks using standard JSON-RPC calls.

A node in a blockchain network is a computer or server that runs blockchain software, participating in verifying and relaying transactions and maintaining the blockchain's integrity and security.
---

## What Are RPC Nodes?

RPC (Remote Procedure Call) nodes allow developers to interact with blockchain networks without the need to run their own full node. By sending **JSON-RPC** requests to Moralis RPC Nodes, you can:

- Query blockchain data (e.g., block and transaction information).
- Interact with smart contracts.
- Fetch NFT and token balances.
- Send transactions and monitor on-chain events.

Moralis simplifies this process by providing reliable, scalable access to RPC nodes across major blockchain networks.

---

## Key Features of Moralis RPC Nodes

Here are some key benefits of using Moralis RPC Nodes:

- **Multi-Chain Support**: Access RPC nodes for Ethereum, Binance Smart Chain, Polygon, Avalanche, and other popular blockchains.
- **High Performance**: Low-latency, reliable infrastructure for handling large amounts of traffic.
- **JSON-RPC Standard**: Fully compliant with the JSON-RPC 2.0 specification, ensuring compatibility with existing Ethereum and EVM-compatible blockchain tools.
- **Extended RPC Methods**: In addition to standard methods, Moralis offers **extended RPC methods** for advanced functionalities like fetching token balances, NFTs, and transaction history.

---

## Getting Started

Ready to start using Moralis RPC Nodes? Here’s what you need to do:

1. **Create a Moralis Account**: [Sign up](https://admin.moralis.io/) for free and access your RPC nodes.
2. **Set Up Your Node**: Visit our [Setting Up RPC Nodes](./get-your-node-api-key) guide to create and configure your RPC node.
3. **Make Your First RPC Call**: Once you have your node set up, follow our [tutorial](./make-your-first-rpc-call) to make your first JSON-RPC call using `ethers.js`.

---

## Supported Networks

Moralis supports a wide variety of blockchain networks, including:

- **Ethereum** (Mainnet and Testnets)
- **Binance Smart Chain**
- **Polygon**
- **Avalanche**
- **Fantom**
- **Arbitrum**
- **Optimism**

For a complete list of supported networks, check out the [Supported Networks](./supported-networks) page.

RPC (Remote Procedure Call) Nodes are essential infrastructure components that enable interaction with various EVM (Ethereum Virtual Machine) blockchains. RPC Nodes are therefore crucial for developing and deploying blockchain applications. They enable developers to deploy and interact with smart contracts, retrieve blockchain data, and perform blockchain integrations with traditional applications.
---

## JSON-RPC and Extended RPC Methods

Moralis offers full support for the standard **JSON-RPC** 2.0 specification, making it easy to integrate with any existing Ethereum or EVM-compatible tools.

In addition to standard JSON-RPC methods, Moralis provides **extended RPC methods** that allow for more advanced queries, such as:

- Fetching token balances.
- Fetching NFT holdings.
- Fetching transaction history.

To learn more about the available methods, visit the [Standard vs Extended RPC Methods](./rpc-methods) page.

---

## Rate Limiting and Usage Limits

Moralis enforces rate limits at the **account level** to ensure fair usage across all users. Each account has a set number of allowed requests per minute, based on your plan. For more information on rate limits and how to optimize your usage, visit our [FAQ](/rpc-faqs) page.

---

## Next Steps

- [Setting Up RPC Nodes](./get-your-node-api-key): Learn how to set up your first RPC node.
- [Fetching ERC20 Balances](./tutorials/fetching-erc20-token-balances): Step-by-step guide on how to fetch token balances.
- [Fetching Wallet Transactions](./tutorials/fetching-wallet-transactions): Guide for retrieving all transactions associated with a wallet.

---

## Need Help?

If you have any questions or need further assistance, check out our [FAQ](/rpc-faqs) or reach out to our support team.

---

Moralis provides access to the [Ethereum JSON-RPC API method library](https://ethereum.org/en/developers/docs/apis/json-rpc/) that interacts with the Ethereum blockchain all supported EVM blockchains, providing developers with robust and efficient access to blockchain functionalities. Methods include functionality for reading and writing data to the network, and executing smart contracts.
Happy building with Moralis RPC Nodes!
6 changes: 3 additions & 3 deletions docs/07-rpc-nodes/03-public-node-endpoints.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "RPC Node Endpoints"
slug: "/public-rpc-node-endpoints"
sidebar_label: "RPC Node Endpoints"
title: "Supported Networks"
slug: "/supported-networks"
sidebar_label: "Supported Networks"
sidebar_position: 3
sidebar_class_name: "sidebar-overview"
hide_table_of_contents: true
Expand Down
77 changes: 77 additions & 0 deletions docs/07-rpc-nodes/fundamentals/how-json-rpc-works.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
title: "How JSON-RPC Works"
slug: "/how-json-rpc-works"
sidebar_label: "How JSON-RPC Works?"
sidebar_position: 1
---

JSON-RPC operates in a straightforward request-response model, allowing developers to call methods on remote servers with minimal configuration. The client sends a JSON-encoded request to a server, which processes the request and returns a JSON-encoded response.

### Components of JSON-RPC

1. **Request**

- The client sends a request containing:
- `jsonrpc`: The protocol version (e.g., "2.0").
- `method`: The name of the method being invoked.
- `params`: An array or object containing the method's parameters.
- `id`: A unique identifier to match the response.

2. **Response**
- The server responds with:
- `result`: The result of the method invocation.
- `id`: The same `id` from the request to match the response.
- `error`: Optional, only present if the request fails.

### Example of a JSON-RPC Flow

1. **Client Request**:

```json
{
"jsonrpc": "2.0",
"method": "eth_getBlockByNumber",
"params": ["0x10d4f", true],
"id": 1
}
```

2. **Server Response**:
```json
{
"jsonrpc": "2.0",
"result": {
"number": "0x10d4f",
"hash": "0xabc123...",
"transactions": [...]
},
"id": 1
}
```

This simplicity makes JSON-RPC an ideal choice for systems where performance, minimalism, and ease of use are priorities, such as querying blockchain data.

### Batch Requests

JSON-RPC supports sending multiple requests in a single batch, improving performance and reducing latency.

Example:

```json
[
{
"jsonrpc": "2.0",
"method": "eth_getBlockByNumber",
"params": ["0x10d4f", true],
"id": 1
},
{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": ["0x123456..."],
"id": 2
}
]
```

This enables you to execute multiple calls in parallel, reducing overhead and network latency.
41 changes: 41 additions & 0 deletions docs/07-rpc-nodes/fundamentals/json-rpc-basics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: "What is JSON-RPC?"
slug: "/json-rpc-basics"
sidebar_label: "What is JSON-RPC?"
sidebar_position: 0
---

JSON-RPC is a lightweight, remote procedure call (RPC) protocol that uses JSON (JavaScript Object Notation) to encode messages. It allows applications to execute methods on remote systems as if they were local, with the key advantage being its simplicity and minimal overhead.

### Key Features

- **Protocol-Agnostic**: JSON-RPC can be transported over any communication protocol (HTTP, WebSocket, etc.).
- **Stateless Communication**: Each request/response is independent, simplifying the interaction model.
- **Lightweight & Human-Readable**: JSON is both lightweight and easy to parse, making it ideal for efficient communication between distributed systems.

### Example Request and Response

A simple JSON-RPC request might look like this:

```json
{
"jsonrpc": "2.0",
"method": "getBalance",
"params": ["0x123456..."],
"id": 1
}
```

And the corresponding response:

```json
{
"jsonrpc": "2.0",
"result": "100 ETH",
"id": 1
}
```

In this request, we call the getBalance method with a parameter (the wallet address) and receive a response with the balance.

JSON-RPC’s simplicity and flexibility have made it a widely-used protocol, especially in decentralized applications (dApps) that interact with blockchain networks.
53 changes: 53 additions & 0 deletions docs/07-rpc-nodes/fundamentals/json-rpc-in-blockchain-networks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: "JSON-RPC in Blockchain Networks"
slug: "/json-rpc-blockchain-networks"
sidebar_label: "JSON-RPC in Blockchain"
sidebar_position: 2
---

JSON-RPC is the backbone of communication for many blockchain networks, especially those that are Ethereum-compatible. It allows developers to interact with blockchain nodes, retrieve on-chain data, and send transactions. The decentralized nature of blockchain makes JSON-RPC an ideal fit due to its efficiency, statelessness, and lightweight structure.

### Why JSON-RPC in Blockchain?

Blockchain networks, particularly those based on the Ethereum Virtual Machine (EVM), rely on JSON-RPC for various tasks:

- **Querying blockchain data**: Retrieve account balances, transaction details, and block information.
- **Smart contract interaction**: Call smart contract methods, retrieve state variables, and send transactions.
- **Transaction submission**: Submit signed transactions to the blockchain for processing.

### Common JSON-RPC Methods in Blockchain

Here are some of the most commonly used JSON-RPC methods in blockchain development:

- **eth_blockNumber**: Get the latest block number.
- **eth_getTransactionByHash**: Retrieve a transaction by its hash.
- **eth_getBalance**: Get the balance of a wallet address.
- **eth_sendRawTransaction**: Submit a raw transaction to the network.

### JSON-RPC and dApp Development

Decentralized applications (dApps) leverage JSON-RPC to query blockchain nodes for real-time data. Using JSON-RPC, dApps can:

- Monitor wallet balances.
- Interact with decentralized finance (DeFi) protocols.
- Fetch and display NFTs.
- Allow users to submit transactions directly from their wallets.

For example, if you’re building a DeFi dashboard, you might use the following RPC call to fetch the user's wallet balance:

```json
{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": ["0x123456...", "latest"],
"id": 1
}
```

### JSON-RPC in Multi-Chain Development

With the growing adoption of multi-chain ecosystems (e.g., Ethereum, Binance Smart Chain, Polygon), JSON-RPC remains a consistent and universal communication protocol. Developers can use the same RPC methods across multiple chains, making cross-chain development more accessible.

### Conclusion

JSON-RPC’s role in blockchain networks is indispensable. It serves as the communication protocol that powers interactions between dApps, users, and the blockchain itself. As blockchain technology continues to evolve, JSON-RPC remains a critical tool for developers to build decentralized solutions.
77 changes: 77 additions & 0 deletions docs/07-rpc-nodes/fundamentals/standard-vs-extended-rpc-methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
title: "Standard vs Extended RPC Methods"
slug: "/rpc-methods"
sidebar_label: "Standard vs Extended RPC"
sidebar_position: 3
---

When interacting with blockchain networks, **RPC (Remote Procedure Call) methods** are essential for querying data, submitting transactions, and interacting with smart contracts. There are two categories of RPC methods supported by Moralis: **Standard RPC Methods** and **Extended RPC Methods**.

### Standard RPC Methods

**Standard RPC methods** are the foundational set of methods that are available on most EVM (Ethereum Virtual Machine) compatible blockchains, including Ethereum, Binance Smart Chain, Polygon, and others. These methods are typically defined by the Ethereum JSON-RPC specification and provide the basic functionality required to interact with a blockchain.

#### Common Standard RPC Methods:

- **eth_blockNumber**: Returns the latest block number.
- **eth_getBalance**: Retrieves the balance of a given account.
- **eth_call**: Executes a call to a smart contract without submitting a transaction.
- **eth_sendTransaction**: Sends a transaction to the blockchain.
- **eth_getTransactionByHash**: Retrieves the details of a transaction by its hash.
- **eth_getLogs**: Fetches event logs from smart contracts.

These methods enable developers to:

- Query blockchain data (e.g., block, transaction, or account data).
- Send transactions and interact with smart contracts.
- Monitor event logs and contract executions.

Standard RPC methods are ideal for performing basic blockchain operations, such as querying balances, submitting transactions, or deploying contracts.

### Extended RPC Methods

**Extended RPC methods**, provided by Moralis, go beyond the standard methods by offering more specialized, complex, and aggregated functionalities. These methods allow developers to retrieve more comprehensive data or perform advanced operations that are not available through standard methods. Extended methods simplify complex blockchain interactions, reducing the need to make multiple requests to achieve a single task.

#### Common Extended RPC Methods:

- **eth_getTokenBalances**: Retrieves all ERC20 token balances of a given wallet address in one call.
- **eth_getNFTBalances**: Fetches all NFTs held by a specific wallet.
- **eth_getDecodedTransactions**: Returns transaction history for a wallet, with decoded data for easier interpretation.
- **eth_getTokenPrice**: Retrieves the price of a specific ERC20 token by its contract address.
- **eth_getTokenMetadata**: Provides metadata for a given ERC20 token, such as its name, symbol, and decimals.

These extended methods offer:

- **Aggregated Data Retrieval**: Fetch all token balances or NFT holdings for a wallet in one request, rather than querying each token individually.
- **Decoded Data**: Obtain transaction history or smart contract interactions in a human-readable format, reducing the need for manual decoding.
- **Advanced Queries**: Retrieve data that typically requires multiple standard calls, simplifying the integration and improving performance.

### Key Differences

| Feature | Standard RPC Methods | Extended RPC Methods |
| ------------------ | ------------------------------------------------------------------ | ---------------------------------------------------------------------- |
| **Scope** | Basic blockchain interactions | Advanced and aggregated functionalities |
| **Complexity** | Standardized and relatively simple methods | More specialized, often combining multiple actions into one request |
| **Data Retrieval** | Requires multiple requests for complex data (e.g., token balances) | Fetches aggregated data in a single request (e.g., all token balances) |
| **Usability** | Requires more manual processing and multiple queries | Provides decoded, human-readable data |
| **Availability** | Available on all EVM-compatible chains | Available via Moralis for enhanced functionality |

### When to Use Standard vs Extended Methods

- **Standard RPC Methods**: Use these for basic operations, such as querying account balances, sending transactions, or interacting with deployed smart contracts.

- Examples:
- Checking the balance of an Ethereum address.
- Sending ETH or an ERC20 token.
- Retrieving transaction details by hash.

- **Extended RPC Methods**: Use these for more advanced use cases that require detailed or aggregated data, such as fetching all token balances or NFT holdings of a wallet, retrieving decoded transaction history, or getting token metadata.

- Examples:
- Fetching all ERC20 token balances or NFTs in one call.
- Obtaining decoded transaction history for a wallet.
- Querying token metadata and prices for multiple tokens in one request.

### Conclusion

Both standard and extended RPC methods serve important roles in blockchain development. Standard methods are great for simple interactions and are widely supported across EVM-compatible networks. Extended methods, on the other hand, provide developers with advanced capabilities, enabling more complex data retrieval and reducing the overhead of multiple requests. By leveraging both, you can build efficient and powerful blockchain applications that meet a wide range of user needs.
10 changes: 10 additions & 0 deletions docs/07-rpc-nodes/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: "Getting Started"
sidebar_position: 2
slug: "/rpc-nodes/getting-started"
sidebar_class_name: "sidebar-getting-started"
---

import DocCardList from '@theme/DocCardList';

<DocCardList />
Loading

0 comments on commit 3c83579

Please sign in to comment.