Skip to content

Ethers.js JavaScript Library

Intro diagram


The ethers.js library provides a set of tools to interact with Ethereum Nodes with JavaScript, similar to web3.js. Moonbeam has an Ethereum-like API available that is fully compatible with Ethereum-style JSON RPC invocations. Therefore, developers can leverage this compatibility and use the ethers.js library to interact with a Moonbeam node as if they were doing so on Ethereum. You can read more about ethers.js on this blog post.

Setup Ethers.js with Moonbeam

To get started with the ethers.js library, install it using the following command:

npm install ethers

Once done, the simplest setup to start using the library and its methods is the following:

const ethers = require('ethers');

// Variables definition
const privKey = '0xPRIVKEY';

// Define Provider
const provider = new ethers.providers.StaticJsonRpcProvider('RPC_URL', {
    chainId: ChainId,
    name: 'NETWORK_NAME'

// Create Wallet
let wallet = new ethers.Wallet(privKey, provider);

Different methods are available inside provider and wallet. Depending on which network you want to connect to, you can set the network configurations to the following values:

Variable Value
ChainID 1284 (hex: 0x504)
Variable Value
ChainID 1285 (hex: 0x505)
NETWORK_NAME moonriver
Variable Value
ChainID 1287 (hex: 0x507)
NETWORK_NAME moonbase-alpha
Variable Value
ChainID 1281 (hex: 0x501)
NETWORK_NAME moonbeam-development


If you are interested in a more detailed step-by-step guide, you can go to our specific tutorials on using ethers.js on Moonbeam to send a transaction or deploy a contract.