Ethers.js is an open-source JavaScript and TypeScript library for interacting with Ethereum and other EVM-compatible blockchains: it reads chain data, manages keys and signers, encodes calls through a contract’s ABI and sends signed transactions. In the work with smart contracts, it is the layer that connects a web application, script or backend service to deployed contract code.
The library is known for a small footprint, a clear separation between reading and signing, and extensive utilities for units, hashing and address handling. It is released under the MIT license and is widely used alongside development frameworks such as Hardhat.
How Ethers.js is structured
Ethers.js organizes blockchain access around a few core abstractions that keep responsibilities apart. A Provider offers read-only access to a node, a Signer holds or reaches a private key and authorizes transactions, and a Contract object turns ABI definitions into ordinary JavaScript methods.
This split is a deliberate security boundary. Code that only displays balances never needs a key, while code that sends value must obtain a signer explicitly, often from a browser wallet that asks the user to confirm each action. The table below lists the main classes and their roles.
| Class or module | Purpose | Typical use |
|---|---|---|
| Provider | Read-only connection to a node | Balances, blocks, logs, gas prices |
| Signer | Authorizes messages and transactions | Sending ether, calling state-changing functions |
| Wallet | Signer built from a private key | Backend scripts and test accounts |
| Contract | Typed wrapper around a deployed contract | Calling balanceOf or transfer |
| Interface | ABI encoding and decoding | Parsing event logs and revert data |
| Utilities | Units, hashing, addresses | parseUnits, keccak256, getAddress |
Providers, signers and contract calls in practice
Ethers.js supports several provider types that differ in transport and resilience. A JsonRpcProvider connects over HTTP to a node or hosted endpoint, a WebSocketProvider keeps a live channel for event subscriptions, a BrowserProvider wraps a wallet extension, and a FallbackProvider queries several backends and compares results.
Contract interaction follows two paths. Read calls to view or pure functions run locally on the node and cost no gas. Write calls produce a transaction that must be signed, broadcast and mined; the method returns a transaction response, and calling wait() returns the receipt with status and emitted events.
| Aspect | Read call | Write call |
|---|---|---|
| Requires signer | No | Yes |
| Gas cost | None for the caller | Paid in the native token |
| Result | Decoded return value | Transaction response, then receipt |
| Changes state | No | Yes, after inclusion in a block |
| Failure mode | Revert error returned at once | Revert during estimation or execution |
Events are handled through filters and listeners. Applications can query historical logs with queryFilter or subscribe to new events, and the Interface class decodes the raw log topics into named arguments.
Version 5 and version 6 differences
The major release Ethers.js version 6, published in 2023, modernized the library and introduced breaking changes. Its most visible change is the switch from a custom BigNumber class to the native JavaScript bigint type, which removes a whole category of conversion errors but requires code updates.
| Area | Version 5 | Version 6 |
|---|---|---|
| Large numbers | BigNumber class | Native bigint |
| Browser wallet provider | Web3Provider | BrowserProvider |
| Utility namespace | Grouped under ethers.utils | Exported at top level |
| Language target | Older JavaScript runtimes | ES2020 and later |
Many tutorials and older projects still use version 5 syntax, so mixing examples across versions is a frequent source of confusion. Teams migrating should update numeric handling first, since arithmetic between bigint and ordinary numbers throws errors by design.
Ethers.js compared with related tools
Ethers.js sits in a small family of EVM client libraries and works alongside, not instead of, development frameworks. Web3.js was the earliest widely used library, but its maintainers announced its sunset in 2025. Viem is a newer TypeScript-first library that emphasizes strict typing and modular imports.
| Tool | Category | Relationship to Ethers.js |
|---|---|---|
| Web3.js | Client library | Older alternative, now sunset |
| Viem | Client library | Modern alternative with strict types |
| Hardhat | Development framework | Uses Ethers.js through a plugin in tests |
| Foundry | Development framework | Tests in Solidity; Ethers.js often used for front ends |
| OpenZeppelin | Contract library | Supplies contracts that Ethers.js calls |
Choosing among client libraries is mostly a question of team familiarity, typing needs and bundle size. Ethers.js remains a common default because of its stable API, broad documentation and built-in support for the Ethereum Name Service.
Common mistakes and security considerations
Most problems with Ethers.js come from unit handling, key exposure and incomplete error handling rather than from the library itself. Token amounts must always use integer base units, and private keys must never be shipped to a browser bundle.
- Using floating-point numbers for token amounts instead of
parseUnitswith the correct decimals. - Embedding a private key in front-end code or a public repository.
- Ignoring the receipt status, assuming a broadcast transaction has succeeded.
- Connecting to the wrong chain ID, which leads to failed calls or replay confusion.
- Trusting a single RPC endpoint for critical data without a fallback or confirmation depth.
Developers should also decode revert reasons and custom errors through the contract Interface, set reasonable confirmation counts for high-value operations, and review gas estimates before signing, since an unexpectedly high estimate often signals a failing or malicious call.
Understanding it simply
Ethers.js is a translator between a website and a blockchain. Blockchains speak a strict, technical language of encoded data and digital signatures, while web applications speak JavaScript. The library converts between the two.
When an app needs to show a balance, Ethers.js asks the network and returns a readable number. When the app needs to send a payment, Ethers.js prepares the request and passes it to the user’s wallet for approval. The app never needs to hold the secret key.
Applied in practice
A small team builds a donation page for a community project that accepts a dollar-pegged token on an Ethereum layer 2 network. The front end uses a BrowserProvider to connect to the visitor’s wallet and a read-only JsonRpcProvider to display the running donation total without asking anyone to connect first.
When a donor enters 25 tokens, the code converts the amount with parseUnits using 6 decimals, calls transfer on the token contract, and waits for one confirmation before showing a thank-you message with the transaction hash. A backend script, also written with Ethers.js, listens for Transfer events to the project address and records each donation in an accounting sheet. During testing, the team catches a bug where amounts were multiplied by 18 decimals instead of 6, which would have requested a trillion times the intended value; the wallet confirmation screen exposed the mistake before any funds moved.