Web3.js is an open-source JavaScript library that lets web pages, Node.js services and scripts communicate with Ethereum and other EVM-compatible blockchains through a node’s JSON-RPC interface. In the domain of Smart contracts within Crypto & blockchain, it was for years the default bridge between a dApp front end and deployed contracts, handling account access, transaction signing, contract calls and event subscriptions.
The library began in 2014 alongside the Ethereum client software and was later maintained by ChainSafe. Its version 4 rewrite in TypeScript modernized the codebase, yet in early 2025 the maintainers announced the project’s sunset, so new projects increasingly choose alternatives such as Ethers.js or viem.
How Web3.js talks to a blockchain node
Web3.js works as a client-side wrapper around JSON-RPC methods such as eth_call, eth_sendRawTransaction and eth_getLogs. The application creates a Web3 instance bound to a provider, an object that knows how to deliver requests to a node, and the library converts readable method calls into correctly encoded RPC messages and decodes the responses.
The provider determines who signs and where requests go. A browser wallet such as MetaMask injects an EIP-1193 provider, which keeps private keys inside the wallet and asks the user to approve each transaction, while a backend service typically uses an HTTP or WebSocket endpoint together with a locally held key.
The table below compares the provider types a developer can configure.
| Provider type | Typical use | Main constraint |
|---|---|---|
| Injected EIP-1193 provider | Browser dApps with a wallet | User must approve every signature |
| HTTP provider | Backend reads and scripted writes | No push events; polling required |
| WebSocket provider | Real-time event subscriptions | Connections drop and need reconnection |
| IPC provider | Server co-located with a node | Works only on the same machine |
Provider choice also shapes reliability. Public RPC endpoints apply rate limits and occasional inconsistencies between load-balanced nodes, so production services often run their own node or use several providers with fallback logic.
Core modules and what they do
Web3.js is organized into modular packages, so applications can import only the parts they need and reduce bundle size. Version 4 made this split explicit and added TypeScript type inference for contract methods generated from an ABI.
| Package | Purpose | Example operation |
|---|---|---|
| web3-eth | Chain queries and transactions | Read a balance or block |
| web3-eth-contract | ABI-based contract interaction | Call a token transfer method |
| web3-eth-accounts | Local key management and signing | Sign a transaction offline |
| web3-eth-abi | Encode and decode call data | Decode an event log |
| web3-utils | Units, hashing and conversions | Convert Ether to wei |
Interaction with a contract starts from its Application Binary Interface (ABI) and address. Read-only methods use call, which executes on the node without a transaction or gas fee, while state-changing methods use send, which builds a transaction, requests a signature and returns a receipt after the transaction is mined. Developers must still choose a sensible gas limit and fee parameters, or rely on the library’s estimation.
Web3.js compared with Ethers.js and viem
Web3.js, Ethers.js and viem solve the same problem with different design philosophies. The choice affects bundle size, type safety, maintenance outlook and how wallet and node responsibilities are separated.
| Library | Design approach | Maintenance outlook |
|---|---|---|
| Web3.js | Large, object-oriented, batteries included | Sunset announced in 2025 |
| Ethers.js | Compact, strict provider and signer split | Actively maintained |
| viem | Functional, tree-shakable, strongly typed | Actively maintained |
Ethers.js popularized the separation of provider and signer, which makes it harder to accidentally mix read access with key custody. Web3.js historically bundled these roles into one object, which is convenient but encourages keys to be loaded into the same context as application logic. The difference matters most in backend services that sign transactions automatically.
Working with Web3.js in practice
Typical Web3.js workflows follow a repeatable sequence: connect a provider, load the ABI, read state, prepare a transaction, sign it and wait for confirmation. Development environments such as Hardhat, Foundry and Remix IDE produce the ABI and run local test chains against which the same code can be exercised.
- Create a
Web3instance with the wallet or node provider. - Instantiate a contract object from the ABI and deployed address.
- Use
callto read state such as balances or allowances. - Use
sendor sign locally, then broadcast the raw transaction. - Wait for the receipt and check its status field and emitted events.
Numeric handling deserves care. Token amounts are integers in the smallest unit, and Web3.js version 4 returns BigInt values by default; code written for version 1, which returned strings or BN objects, often breaks silently during migration.
Pitfalls and security considerations
Most Web3.js incidents stem from application mistakes rather than library flaws. The library faithfully sends what the developer asks for, so errors in units, key handling or confirmation logic translate directly into lost funds or failed transactions.
| Mistake | Consequence | Fix |
|---|---|---|
| Private key in front-end code | Anyone can drain the account | Sign only through the user’s wallet |
| Ether and wei confusion | Amounts off by a factor of 10^18 | Convert with utility functions |
| Treating send as final | Logic runs before confirmation | Wait for receipt and required confirmations |
| Ignoring reorganizations | Events later disappear | Track block confirmations before acting |
| Unpinned dependency versions | Supply-chain compromise risk | Lock versions and audit updates |
Because the project is no longer actively developed, teams maintaining existing Web3.js code should plan a migration path, freeze audited versions and monitor security advisories. The library remains readable and functional, but unpatched dependencies become a growing risk over time.
In everyday language
A blockchain node speaks a technical language that ordinary websites do not understand. Web3.js is a translator written in JavaScript: a website asks it to check a balance or run a contract function, and the library turns that request into the exact message the node expects.
It does not hold money and it is not a wallet. It simply carries requests between an app, a wallet and the blockchain, which is why one careless line of code can still send funds to the wrong place.
Seen in the real world
A community art collective runs a small website where members mint commemorative tokens from an existing ERC-721 contract. The front end uses Web3.js with the visitor’s injected browser wallet, so private keys never touch the site. When a member clicks the mint button, the page calls the contract’s price function with call, then sends the mint transaction with send, and the wallet shows a confirmation dialog.
The page waits for the receipt and two block confirmations before displaying the new token. After the maintainers announced the sunset, the collective pinned the library version and scheduled a gradual migration to viem, keeping the site working while reducing long-term maintenance risk.