• Ankr Build
  • Supported Chains
  • Moonbeam

Moonbeam

Moonbeam combines the easy-to-use tooling of Ethereum and the scalable, interoperable architecture of Polkadot. Moonbeam is EVM compatible to an extent but there are important Moonbeam differences that developers should know and understand in terms of the Ethereum API JSON-RPC support.

Quick links

Moonbeam

Docs

Github


Connect wallet

You can set up your MetaMask wallet to connect to Moonbeam RPC. You can then perform transactions and interact with the network.

  1. Open your Metamask Extension and click the 'Network' drop down menu at the top.
  2. Select 'Custom RPC'.
  3. Enter the settings for the required project as follows in the table below:
ChainCustom RPC CategoryDetails
CeloNETWORK NAME:Moonbeam RPC
NEW RPC URL:https://rpc.ankr.com/moonbeam/
CHAIN ID:1284 (hex: 0x504)
SYMBOL:GLMR
BLOCK EXPLORER URL:https://moonscan.io/

Get Started

Using Ethereum API Libraries

The Moonbeam API is very similar to the Ethereum API and is compatible with the majority of Ethereum-style JSON-RPC methods. Developers can leverage this compatibility and use the web3.js library, ethers.js library and the web3.py library to interact with a Moonbeam node as if they were doing so on Ethereum.

However, not all Ethereum JSON RPC methods are supported, and some of the supported ones return default values.

The following methods are supported on the Moonbeam RPC.

How to integrate with Moonbeam

If you're using the Public RPCs, your endpoint is https://rpc.ankr.com/moonbeam.

If you're using the Premium Plan, you can copy your two endpoints for HTTPS and WSS from Ankr Protocol

💡

In the code samples below, use EITHER the public endpoint OR the premium endpoint (if you have signed up to the Premium Plan)

const Web3 = require('web3'); //Load Web3 library

// Create local Web3 instance - set Moonbeam as provider
const web3 = new Web3("https://rpc.ankr.com/moonbeam"); // Public RPC URL

const web3 = new Web3("https://rpc.ankr.com/moonbeam/YOUR-API-KEY"); // Premium RPC URL
const ethers = require('ethers');

const providerURL = "https://rpc.ankr.com/moonbeam"; // Public RPC URL

const providerURL = "https://rpc.ankr.com/moonbeam/YOUR-API-KEY"; // Premium RPC URL

// Define Provider
const provider = new ethers.providers.StaticJsonRpcProvider(providerURL, {
    chainId: 1284,
    name: 'moonbeam'
});

Using Substrate API libraries

Polkadot.js API library allows application developers to query a Moonbeam node and interact with the node's Polkadot or Substrate interfaces using JavaScript.

  1. Install node.js (if not already installed)

    # homebrew (https://docs.brew.sh/Installation)
    brew install node
     
    # nvm (https://github.com/nvm-sh/nvm)
    nvm install node
  2. Install Polkadot.js API library

    You can install this through a package manager such as yarn. Install it in your project directory with the following command:

    yarn add @polkadot/api
    
  3. Install Moonbeam Types Bundle

    To decode Moonbeam custom events and types, you need to include the Moonbeam Types Bundle into your project by adding the following package information to your package.json:

    "@polkadot/api": "^6.9.1",
    "moonbeam-types-bundle": "^2.0.1",
    "typescript": "4.3.2"
  4. Add this import statement

    Add this statement to the start of your project file.

    import { typesBundlePre900 } from "moonbeam-types-bundle"
Last updated on September 12, 2022