Web3.js vs Ethers.js: Which Ethereum Library to Use
Comparing Web3.js and Ethers.js, the two dominant JavaScript libraries for interacting with Ethereum nodes and smart contracts.
Web3.js and Ethers.js are the two most widely used JavaScript libraries for building applications that interact with Ethereum — connecting to nodes, reading blockchain data, sending transactions, and calling smart contract functions from a website or backend service. Both accomplish largely the same underlying tasks, but differ in API design, bundle size, and documentation style.
What these libraries actually do
Neither library runs on the blockchain itself; they're tools used by frontend and backend applications to communicate with an Ethereum node — whether a locally run node, a node operated by an infrastructure provider, or a browser wallet extension acting as the connection point. Practically, this means handling tasks like reading an account balance, formatting and sending a transaction, encoding and decoding contract function calls using a contract's /blog/what-is-an-abi-ethereum, and listening for on-chain events emitted by a contract.
Web3.js
Web3.js is the older of the two libraries and was, for years, the default choice for Ethereum development, closely associated with the Ethereum Foundation's early tooling efforts. It has broad historical documentation and remains present in a large number of existing tutorials and legacy codebases, which is part of why it's still commonly encountered, even though newer projects increasingly favor its more modern counterpart.
Ethers.js
Ethers.js was designed with a more deliberately minimal, modular architecture and has become the more commonly recommended choice for new projects in recent years. Its API is generally considered more intuitive for handling the numeric precision Ethereum requires (since ETH amounts are represented in extremely small base units, and floating-point arithmetic can introduce rounding errors that matter a great deal when real value is involved), and its smaller bundle size makes it a lighter dependency for frontend applications.
Comparing the two libraries
| Aspect | Web3.js | Ethers.js |
|---|---|---|
| Age / origin | Older, historically the default | Newer, designed with a more modular approach |
| Bundle size | Larger | Generally smaller |
| Numeric precision handling | Functional but less ergonomic | Widely regarded as more intuitive |
| Current momentum | Declining relative adoption for new projects | Preferred by many newer projects and tutorials |
| Documentation | Extensive historical documentation | Strong, actively maintained documentation |
Practical considerations when choosing
For a brand-new project without existing constraints, Ethers.js is generally the more commonly recommended starting point today, given its more modern design and growing ecosystem support. For a project already built around Web3.js — particularly an older, established codebase — a full migration isn't always worth the effort purely for its own sake, since both libraries are capable of accomplishing the same core tasks reliably.
Where these libraries fit in the broader stack
These libraries typically sit between a frontend or backend application and either a browser wallet (see /blog/how-to-choose-an-ethereum-wallet) or a directly connected node provider. On the smart contract development side, frameworks like the ones compared in /blog/what-is-hardhat-vs-truffle often use one of these libraries internally as part of their deployment and testing scripts, meaning developers frequently encounter both a framework and one of these libraries together rather than choosing entirely independently.
Migrating between the two
Because both libraries ultimately serve the same purpose, migrating an existing project from one to the other is a well-trodden path, and many teams have done it as Ethers.js's ecosystem momentum grew. That said, migration isn't always trivial — differences in how each library represents numeric values, formats addresses, and structures asynchronous calls mean a direct line-by-line swap rarely works cleanly, and a careful migration usually involves re-testing thoroughly rather than assuming equivalent behavior by default. For a project already functioning reliably on Web3.js, this migration effort is only worth undertaking if there's a concrete reason to do so, rather than switching purely to follow current trends.
Security considerations when using either library
Regardless of which library is used, applications built with them are only as secure as how carefully they handle private keys, transaction confirmation flows, and contract call encoding — the library itself doesn't protect against a poorly designed application flow that, for example, requests overly broad token approvals from users, a risk discussed in /blog/how-token-approvals-work-ethereum. Neither library replaces careful application-level security practices or a proper /blog/how-to-audit-a-smart-contract for the underlying contracts being called.
Beyond the browser: backend and scripting use
Both libraries are used well beyond simple browser-based frontends. Backend services, automated trading or monitoring scripts, and the deployment scripts used by frameworks like the ones compared in /blog/what-is-hardhat-vs-truffle commonly rely on one of these two libraries to communicate directly with an Ethereum node without any browser wallet involved at all, typically authenticating instead with a directly held private key or a node provider's API credentials. This backend usage pattern carries its own security considerations, since a private key embedded in a script or server environment needs to be protected with the same seriousness as one held in a personal wallet.
Bottom line
Web3.js and Ethers.js both provide the same essential bridge between JavaScript applications and Ethereum nodes, but Ethers.js has become the more commonly recommended choice for new projects due to its more modern, modular design and smaller footprint, while Web3.js remains relevant mainly through its large base of existing documentation and legacy codebases.
Related articles
This article is for educational purposes only and is not financial advice. DeFi involves significant risk, including total loss of funds. Always do your own research.