Docs

Moonbeam RPC with Dwellir

Moonbeam RPC endpoints for Mainnet and Moonriver; EVM JSON-RPC quickstarts for curl, ethers.js, viem, and web3.py

Moonbeam RPC

With Dwellir, you get access to our global Moonbeam network which always routes your API requests to the nearest available location, ensuring low latency and the fastest speeds.

Get your API key

Why Build on Moonbeam?

Moonbeam is the leading Ethereum-compatible smart contract platform on Polkadot, offering seamless EVM compatibility with powerful cross-chain capabilities:

Native Cross-Chain Integration

  • Universal Connectivity - Connect with 50+ blockchains via Axelar, LayerZero, Wormhole, and Hyperlane
  • Bridge-Free Communication - Direct cross-chain messaging without traditional bridges
  • Multi-Chain dApps - Build applications that interact with Ethereum, Polygon, Avalanche, and more

Full Ethereum Compatibility

  • 100% EVM Compatible - Deploy existing Solidity contracts without modification
  • Familiar Tooling - Use MetaMask, Hardhat, Remix, and other Ethereum tools
  • Web3 API Mirror - Complete Ethereum Web3 RPC implementation

Polkadot Ecosystem Benefits

  • Shared Security - Protected by Polkadot's validator network
  • On-Chain Governance - Community-driven protocol upgrades
  • Substrate Framework - Advanced features beyond standard EVM

Quick Start with Moonbeam

Connect to Moonbeam in seconds with Dwellir's optimized endpoints:

Moonbeam RPC Endpoints
HTTPS
curl -sS -X POST https://api-moonbeam.n.dwellir.com/<API_Keys_Are_Not_Made_for_Bots> \  -H 'Content-Type: application/json' \  -d '{"jsonrpc":"2.0","method":"chain_getBlockHash","params":[0],"id":1}'
import { JsonRpcProvider } from 'ethers';const provider = new JsonRpcProvider(  'https://api-moonbeam.n.dwellir.com/<API_Keys_Are_Not_Made_for_Bots>');const latest = await provider.getBlockNumber();console.log('block', latest);
import requestsurl = 'https://api-moonbeam.n.dwellir.com/<API_Keys_Are_Not_Made_for_Bots>'payload = {  'jsonrpc': '2.0', 'id': 1,  'method': 'chain_getBlockHash', 'params': [0]}resp = requests.post(url, json=payload)print(resp.json())
package mainimport (  "bytes"  "fmt"  "io"  "net/http")func main() {  url := "https://api-moonbeam.n.dwellir.com/<API_Keys_Are_Not_Made_for_Bots>"  payload := []byte(`{"jsonrpc":"2.0","id":1,"method":"chain_getBlockHash","params":[0]}`)  resp, err := http.Post(url, "application/json",    bytes.NewBuffer(payload))  if err != nil { panic(err) }  defer resp.Body.Close()  body, _ := io.ReadAll(resp.Body)  fmt.Println(string(body))}

Installation & Setup

Network Information

ParameterValueDetails
Chain ID1284Mainnet
Block Time12 secondsAverage
Gas TokenGLMRNative token
RPC StandardEthereumEVM Compatible

API Reference

Moonbeam supports the full Ethereum JSON-RPC API specification plus Substrate-specific methods.

Common Integration Patterns

Cross-Chain Messaging

Leverage Moonbeam's native cross-chain capabilities:

JavaScript
// Example: Send message to Ethereum via Axelar
import { AxelarGMPSDK } from '@axelar-network/axelarjs-sdk';

const sdk = new AxelarGMPSDK({
  environment: 'mainnet',
  moonbeamRpcUrl: 'https://api-moonbeam.n.dwellir.com/YOUR_API_KEY'
});

// Send cross-chain transaction
const tx = await sdk.sendToken({
  destinationChain: 'ethereum',
  destinationAddress: '0x...',
  symbol: 'USDC',
  amount: '100'
});

Multi-Asset Transactions

Work with GLMR and XC-20 tokens:

JavaScript
// GLMR balance (native gas token)
const glmrBalance = await provider.getBalance(address);

// XC-20 token balance (ERC-20 compatible)
const tokenContract = new ethers.Contract(
  '0xTokenAddress',
  ['function balanceOf(address) view returns (uint256)'],
  provider
);
const tokenBalance = await tokenContract.balanceOf(address);

Event Filtering with Pagination

Query contract events efficiently:

JavaScript
// Query events with proper pagination
async function getEvents(contract, eventName, fromBlock = 0) {
  const filter = contract.filters[eventName]();
  const events = [];
  const batchSize = 2000; // Recommended batch size
  const latestBlock = await provider.getBlockNumber();

  for (let i = fromBlock; i <= latestBlock; i += batchSize) {
    const toBlock = Math.min(i + batchSize - 1, latestBlock);
    const batch = await contract.queryFilter(filter, i, toBlock);
    events.push(...batch);
  }

  return events;
}

Performance Best Practices

1. Batch Requests

Combine multiple RPC calls for optimal performance:

JavaScript
const batch = [
  { method: 'eth_blockNumber', params: [] },
  { method: 'eth_gasPrice', params: [] },
  { method: 'eth_getBalance', params: [address, 'latest'] }
];

const results = await provider.send(batch);

2. WebSocket Subscriptions

Use WebSockets for real-time updates:

JavaScript
const wsProvider = new ethers.WebSocketProvider(
  'wss://api-moonbeam.n.dwellir.com/YOUR_API_KEY'
);

// Subscribe to new blocks
wsProvider.on('block', (blockNumber) => {
  console.log('New block:', blockNumber);
});

// Subscribe to pending transactions
wsProvider.on('pending', (txHash) => {
  console.log('Pending tx:', txHash);
});

3. Smart Caching

Cache immutable blockchain data:

JavaScript
const cache = new Map();

async function getCachedBlockData(blockNumber) {
  const key = `block_${blockNumber}`;

  if (!cache.has(key)) {
    const block = await provider.getBlock(blockNumber);
    cache.set(key, block);
  }

  return cache.get(key);
}

Troubleshooting Common Issues

Error: "Insufficient funds for gas"

Ensure sufficient GLMR for gas fees:

JavaScript
// Always account for gas in balance checks
const balance = await provider.getBalance(address);
const gasPrice = await provider.getGasPrice();
const gasLimit = await provider.estimateGas(tx);
const gasCost = gasPrice * gasLimit;

if (balance < (tx.value + gasCost)) {
  throw new Error(`Need ${(tx.value + gasCost) - balance} more wei`);
}

Error: "Transaction underpriced"

Use current market gas prices:

JavaScript
// Get current fee data
const feeData = await provider.getFeeData();

const tx = {
  to: recipient,
  value: amount,
  gasPrice: feeData.gasPrice, // Moonbeam uses legacy gas pricing
  gasLimit: 21000n
};

Error: "Rate limit exceeded"

Implement exponential backoff:

JavaScript
async function callWithRetry(fn, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (error) {
      if (error.code === 429 && i < maxRetries - 1) {
        await new Promise(r => setTimeout(r, 2 ** i * 1000));
      } else {
        throw error;
      }
    }
  }
}

Smoke Tests

Test Connection with cURL

Bash
# Test Moonbeam mainnet
curl -X POST https://api-moonbeam.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

# Test Moonriver (testnet)
curl -X POST https://api-moonriver.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}'

Test with Ethers.js

JavaScript
// Test mainnet connection
const mainnetProvider = new JsonRpcProvider(
  'https://api-moonbeam.n.dwellir.com/YOUR_API_KEY'
);

const blockNumber = await mainnetProvider.getBlockNumber();
const network = await mainnetProvider.getNetwork();

console.log('Block number:', blockNumber);
console.log('Chain ID:', network.chainId); // Should be 1284n

Test with Web3.py

Python
from web3 import Web3

# Test connection
web3 = Web3(Web3.HTTPProvider(
  'https://api-moonbeam.n.dwellir.com/YOUR_API_KEY'
))

print('Connected:', web3.is_connected())
print('Chain ID:', web3.eth.chain_id)  # Should be 1284
print('Block number:', web3.eth.block_number)

Migration Guide

Migrating to Dwellir

Replace your existing RPC endpoint with Dwellir:

JavaScript
// Before
const provider = new JsonRpcProvider('https://other-provider.com');

// After
const provider = new JsonRpcProvider(
  'https://api-moonbeam.n.dwellir.com/YOUR_API_KEY'
);

// All existing code works identically
// Same JSON-RPC methods supported
// Same response formats
// Note: Update your API endpoint URL
// Note: Add your Dwellir API key

Migrating from Ethereum

Moonbeam is fully EVM-compatible:

JavaScript
// Your Ethereum contracts work on Moonbeam without changes
const contract = new ethers.Contract(
  contractAddress,
  abi,
  provider // Just change the provider to Moonbeam!
);

// All contract interactions work the same
const result = await contract.someFunction();

Resources & Tools

Official Resources

Cross-Chain Tools

Developer Tools

Need Help?


Start building cross-chain applications on Moonbeam with Dwellir's enterprise-grade RPC infrastructure. Get your API key