πŸ”· What is Ethers.js?

Ethers.js is a JavaScript library for interacting with the Ethereum blockchain.

It works in both frontend (React/Next.js) and backend (Node.js) environments.

You use it to:

- Connect wallets like MetaMask
- Read blockchain data (e.g., balances, block numbers)
- Interact with smart contracts (call/write functions)
- Send ETH and sign messages
- Listen to events on-chain

πŸ“¦ Why Use Ethers.js?

Benefit Description
βœ… Lightweight Much smaller than Web3.js
βœ… Easy to Use Clean, consistent API
βœ… TypeScript support Built-in typing support
βœ… Secure Handles checksum addresses, ENS, etc.
βœ… Flexible Works with all Ethereum-compatible chains (EVM)

πŸ”Œ Basic Concepts

1. Provider

Used to connect to the blockchain (read-only)

const provider = new ethers.providers.Web3Provider(window.ethereum); // browser
const provider = new ethers.providers.JsonRpcProvider("<https://rpc-url>"); // backend

You can use this to:

await provider.getBalance("0x...");     // ETH balance
await provider.getBlockNumber();       // Latest block


2. Signer

Represents a wallet that can sign and send transactions (write)

const signer = provider.getSigner();  // user’s wallet (MetaMask)
const wallet = new ethers.Wallet(PRIVATE_KEY, provider); // backend wallet