Skip to main content
In this guide, you will make your first JSON-RPC call using your Moralis Node URL. We’ll use ethers.js to query the Ethereum blockchain, but you can use any JSON-RPC compatible library.

Prerequisites

  • Node.js installed on your machine.
  • A Moralis Node URL. If you haven’t created one yet, see Get Your API Key.

Step 1: Install Dependencies

Create a new project and install the required packages:
mkdir my-rpc-project
cd my-rpc-project
npm init -y
npm install ethers dotenv

Step 2: Set Up Environment Variables

Create a .env file in your project root and add your Moralis Node URL:
MORALIS_NODE_URL=YOUR_URL_FROM_DASHBOARD

Step 3: Write the Code

Create a file called index.js:
require("dotenv").config();
const { ethers } = require("ethers");

async function main() {
  const provider = new ethers.JsonRpcProvider(process.env.MORALIS_NODE_URL);

  // Get the latest block number
  const blockNumber = await provider.getBlockNumber();
  console.log("Latest block:", blockNumber);

  // Get the balance of an address
  const balance = await provider.getBalance(
    "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
  );
  console.log("Balance:", ethers.formatEther(balance), "ETH");
}

main();

Step 4: Run the Script

node index.js
You should see output like:
Latest block: 19234567
Balance: 1.234 ETH

Using Extended RPC Methods

Moralis provides extended RPC methods that offer richer data beyond standard JSON-RPC. These methods map to Moralis API endpoints:
MethodDescription
eth_getTransactionsGet native transactions by wallet address
eth_getDecodedTransactionsGet decoded wallet history
eth_getTokenBalancesGet ERC20 token balances by wallet
eth_getTokenPriceGet ERC20 token price
eth_getTokenMetadataGet ERC20 token metadata
eth_getNFTBalancesGet NFTs by wallet address
eth_getNFTCollectionsGet NFT collections by wallet
Extended RPC methods have higher compute unit costs than standard methods. See Pricing for details.

Next Steps

  • Pricing — Understand compute unit costs for each RPC method.
  • Batch Requests — Combine multiple requests into a single API call.
  • Rate Limits — Learn about throughput limits per plan.