Getting Started with Ethers.js: A Modern Alternative to Web3.js

As the Ethereum ecosystem matures, developers are constantly looking for tools that offer a balance between simplicity, performance, and security. While Web3.js was once the default choice for interacting with Ethereum, it’s now clear that Ethers.js has set a new standard—particularly for modern dApp development.

In this post, we’ll explore why Ethers.js has become a preferred alternative to Web3.js, examine its architecture, and walk through common use cases to show how it streamlines the development process.

What is Ethers.js?

Ethers.js is a complete Ethereum library for JavaScript and TypeScript environments. It was originally created by Richard Moore and has grown into one of the most widely adopted tools in the Ethereum developer toolkit.

At its core, Ethers.js offers everything you need to:

  • Connect to Ethereum nodes via JSON-RPC, Etherscan, or third-party providers.
  • Manage wallets and sign transactions.
  • Interact with smart contracts.
  • Listen to blockchain events.
  • Handle ENS (Ethereum Name Service) lookups.

But what makes it different from Web3.js isn’t just the feature set—it’s the developer experience.

Why Ethers.js Over Web3.js?

1. Cleaner, Promise-Based API

Ethers.js was built from the ground up with modern JavaScript in mind. Instead of relying on callbacks, everything is promise-based and supports async/await, leading to cleaner, more readable code.

2. First-Class TypeScript Support

Ethers.js includes TypeScript definitions by default. That means fewer bugs, better autocompletion in editors like VS Code, and stronger typing when dealing with contract methods and structures.

3. Lightweight and Modular

The entire Ethers.js library weighs around 88 KB minified, which makes it ideal for browser-based applications. It’s also modular—you can import only what you need, improving performance and reducing bundle size.

4. Built-In Security Considerations

Ethers was designed with secure default behaviors:

  • Immutable objects (most methods return new instances).
  • Automatic nonce management.
  • Internal safeguards against unsafe transaction replays.

5. Active Development and Community Growth

As of 2025, Ethers.js is the preferred choice in newer frameworks like Hardhat, and it’s widely supported across DeFi protocols and tooling ecosystems.

Core Modules in Ethers.js

Ethers is structured around a few well-defined modules:

Provider

This module allows your application to read blockchain data. You can use:

const provider = new ethers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_KEY');

Or for browser-based dApps:

const provider = new ethers.BrowserProvider(window.ethereum);

Signer

A signer represents an Ethereum account capable of signing transactions:

const signer = await provider.getSigner();
const address = await signer.getAddress();

Contract

Used to interact with smart contracts:

const contract = new ethers.Contract(contractAddress, contractABI, signer);
const result = await contract.myFunction();

Wallet

For working with private keys, mnemonics, or creating random wallets:

const wallet = ethers.Wallet.createRandom();

Utils

Includes helper methods for encoding/decoding, unit conversion, hashing, and more:

const wei = ethers.parseEther("1.0");
const eth = ethers.formatEther(wei);

Example: Reading Blockchain Data

Let’s say you want to fetch the ETH balance of a wallet:

const provider = new ethers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_KEY');
const balance = await provider.getBalance('0x742d35Cc6634C0532925a3b844Bc454e4438f44e');
console.log(`Balance: ${ethers.formatEther(balance)} ETH`);

Compare that to Web3.js, which requires more verbose syntax and sometimes manual decoding.

Smart Contract Interaction Example

Assume we have a basic ERC-20 token. Here’s how to get the balance of a wallet:

const contract = new ethers.Contract(tokenAddress, tokenABI, provider);
const balance = await contract.balanceOf(walletAddress);
console.log(`Token Balance: ${ethers.formatUnits(balance, 18)} Tokens`);

Notice how Ethers automatically handles the ABI decoding, decimals formatting, and contract calls in a readable, straightforward way.

Comparison Table: Ethers.js vs Web3.js

FeatureEthers.jsWeb3.js
API StylePromise-based, async/awaitCallback-first, then promises
TypeScript SupportNative and robustPartial (via DefinitelyTyped)
Bundle Size~88 KB~250 KB+
Wallet SupportHD Wallets, JSON KeystoreExternal plugins
ENS IntegrationNativeBasic
DocumentationConcise and modernBroad but inconsistent
Preferred in ToolsHardhat, FoundryTruffle, Ganache (legacy)
Popularity (2025)Rapidly increasingStable, but aging

Final Thoughts

If you’re building for Ethereum today, Ethers.js should be your first choice. It’s modern, secure, developer-friendly, and backed by a fast-growing community. While Web3.js still plays a role in legacy applications and tutorials, most new frameworks and tools are now centered around Ethers.

Whether you’re writing smart contract UIs, building DeFi dashboards, or creating full-stack Web3 apps, Ethers.js gives you the right mix of performance, control, and readability.

Further Reading

Share this content:

Hi, my name is Toni Naumoski, and I’m a Senior Frontend Developer with a passion for blending code and design. With years of experience as a Frontend Developer, Web Designer, and Creative Technologist, I specialize in crafting unique, responsive, and detail-oriented websites and web applications that stand out. I bring deep expertise in HTML, CSS, and JavaScript working fluently with modern frameworks like React, Angular, and Vue, as well as animation libraries like GSAP. My creative side thrives in Photoshop and Figma, and I enjoy extending functionality using tools like Express.js and ChatGPT. My work is guided by high integrity, strong communication, a positive attitude, and a commitment to being a reliable collaborator. I take pride in delivering high-quality digital experiences that are both technically solid and visually compelling.