πŸ’šUnderstanding the EVM provider/signer concepts

In this section you'll learn what a provider and a signer are and how to use them.

The provider

A provider in Ethers.js serves as a bridge between your application and the Ethereum blockchain. It facilitates communication, allowing your application to retrieve information from the Ethereum network. Think of it as a window into the blockchain, providing you with data without exposing the complexities of the underlying infrastructure.

The different types of providers available in ethers:

Declare a provider using ethers:

const { ethers } = require('ethers');

// Replace the moonbeam RPC by your desired RPC provider
const provider = new ethers.providers.JsonRpcProvider(`https://moonbeam.unitedbloc.com`);

// Now you can use the provider to interact with the EVM blockchains
provider.getBlockNumber().then((blockNumber) => {
  console.log('Current Block Number:', blockNumber);
});

The signer

Moving on to the concept of a signer, it plays a crucial role in facilitating transactions on the Ethereum blockchain. A signer is responsible for signing transactions with a private key, providing the necessary authorization to execute actions like sending Ether or interacting with smart contracts.

Use a signer using ethers and send a transaction:

Last updated