Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsMay 14, 2026·3 min de lecture

ethers.js — Complete Ethereum Library and Wallet for JavaScript

ethers.js is a compact, complete library for interacting with the Ethereum blockchain from JavaScript and TypeScript. It separates concerns into Providers (read-only chain access) and Signers (transaction signing), making it straightforward to build DApps, scripts, and backend services that communicate with smart contracts.

Prêt pour agents

Cet actif peut être lu et installé directement par les agents

TokRepo expose une commande CLI universelle, un contrat d'installation, le metadata JSON, un plan selon l'adaptateur et le contenu raw pour aider les agents à juger l'adaptation, le risque et les prochaines actions.

Stage only · 17/100Stage only
Surface agent
Tout agent MCP/CLI
Type
Script
Installation
Stage only
Confiance
Confiance : Established
Point d'entrée
ethers.js
Commande CLI universelle
npx tokrepo install 42775cdc-4f90-11f1-9bc6-00163e2b0d79

Introduction

ethers.js is a widely used JavaScript library for Ethereum development created by Richard Moore. Its design separates the provider (read-only connection) from the signer (wallet with private key), making code simpler and more secure. ethers.js is known for its small footprint, thorough documentation, and TypeScript-first approach.

What ethers.js Does

  • Connects to Ethereum nodes through JSON-RPC, WebSocket, Infura, Alchemy, and Etherscan providers
  • Deploys and interacts with smart contracts via typed Contract objects
  • Manages wallets, signs transactions, and supports HD derivation paths
  • Encodes and decodes ABI data, function selectors, and event logs
  • Resolves ENS names and supports EIP-712 typed data signing

Architecture Overview

The library is structured around four core concepts: Provider (read-only chain access), Signer (write access with a private key or hardware wallet), Contract (typed interface to deployed contracts), and Utils (encoding, hashing, formatting). In v6, the library is split into sub-packages for tree-shaking. The provider layer abstracts multiple backend transports behind a unified interface, while Contract objects automatically generate callable methods from ABI definitions.

Self-Hosting & Configuration

  • Install with npm install ethers for the full bundle or import sub-paths for smaller builds
  • Create a provider by passing an RPC URL to JsonRpcProvider or use BrowserProvider for MetaMask
  • Instantiate wallets with new ethers.Wallet(privateKey, provider) for signing
  • Use Contract factory with address + ABI + signer/provider to interact with deployed contracts
  • Configure custom networks by passing chain ID and RPC details to the provider constructor

Key Features

  • Small bundle size compared to alternatives, with tree-shakeable sub-packages in v6
  • Provider/Signer separation enforces security best practices
  • Human-readable ABI format simplifies contract interface definitions
  • Built-in ENS support for resolving .eth names to addresses
  • Extensive TypeScript typings with inferred contract method signatures

Comparison with Similar Tools

  • web3.js — Larger API surface with plugin system; ethers.js is leaner with clearer abstractions
  • Viem — Newer TypeScript library with composable actions; ethers.js has a larger existing user base
  • Wagmi — React hooks built on Viem; ethers.js is framework-agnostic and lower level
  • Alchemy SDK — Wraps ethers.js with Alchemy-specific features; ethers.js is provider-neutral

FAQ

Q: Should I use ethers.js v5 or v6? A: v6 is the current release with improved TypeScript support and smaller bundles. v5 is still widely used but will receive only critical fixes.

Q: How do I connect to MetaMask in a browser? A: Use new ethers.BrowserProvider(window.ethereum) to wrap the injected provider and request account access.

Q: Can ethers.js work with Layer 2 networks? A: Yes. Point the provider to any EVM-compatible RPC endpoint (Arbitrum, Optimism, Base, Polygon).

Q: Is ethers.js suitable for backend use? A: Yes. It works in Node.js for indexers, bots, and backend services alongside browser DApps.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires