Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsMay 14, 2026·3 min de lectura

web3.js — Ethereum JavaScript API for DApp Development

web3.js is a collection of TypeScript libraries that let JavaScript and TypeScript applications interact with Ethereum nodes via JSON-RPC. It handles account management, contract deployment, transaction signing, event subscriptions, and ABI encoding. web3.js is one of the foundational libraries of the Ethereum DApp ecosystem.

Listo para agents

Este activo puede ser leído e instalado directamente por agents

TokRepo expone un comando CLI universal, contrato de instalación, metadata JSON, plan según adaptador y contenido raw para que los agents evalúen compatibilidad, riesgo y próximos pasos.

Stage only · 17/100Stage only
Superficie agent
Cualquier agent MCP/CLI
Tipo
Script
Instalación
Stage only
Confianza
Confianza: Established
Entrada
web3.js
Comando CLI universal
npx tokrepo install 145b41ca-4f90-11f1-9bc6-00163e2b0d79

Introduction

web3.js is one of the original JavaScript libraries for interacting with the Ethereum blockchain. Created in 2015, it provides a comprehensive API for reading chain state, sending transactions, deploying contracts, and subscribing to events. It remains widely referenced in tutorials and production DApps.

What web3.js Does

  • Connects to Ethereum nodes via HTTP, WebSocket, or IPC providers
  • Encodes and decodes contract calls using ABI definitions
  • Signs and sends transactions from local or injected wallets
  • Subscribes to real-time events such as new blocks, pending transactions, and log filters
  • Provides utility functions for unit conversion, hashing, and address checksum validation

Architecture Overview

web3.js v4 is a modular TypeScript rewrite organized into packages: web3-eth for core chain interaction, web3-eth-contract for smart contract abstraction, web3-eth-accounts for signing, web3-utils for helpers, and web3-net for network info. A central Web3 class ties them together and manages the provider connection. Plugins extend functionality without modifying the core.

Self-Hosting & Configuration

  • Install with npm install web3 or import individual sub-packages for smaller bundles
  • Set the provider to a public RPC endpoint (Infura, Alchemy) or your own Geth/Reth node
  • Configure gas price strategies using web3.eth.calculateFeeData() for EIP-1559 transactions
  • Use web3.eth.accounts.wallet to manage local signing keys
  • Enable WebSocket provider for real-time subscriptions (new Web3.providers.WebsocketProvider(url))

Key Features

  • Plugin system allows community extensions without forking the core library
  • First-class TypeScript support with full type inference on contract methods
  • ENS (Ethereum Name Service) resolution built in
  • Supports batch JSON-RPC requests for reducing network round trips
  • Compatible with browser, Node.js, and React Native environments

Comparison with Similar Tools

  • ethers.js — Lighter API with separate provider/signer pattern; web3.js uses a unified Web3 object
  • Viem — Modern TypeScript-first alternative with tree-shaking; web3.js has broader legacy ecosystem support
  • Wagmi — React hooks layer built on Viem; web3.js is framework-agnostic
  • Alchemy SDK — Wraps ethers.js with managed services; web3.js is provider-independent

FAQ

Q: Is web3.js still maintained? A: The 4.x branch received active development through ChainSafe. The repository is now archived, but the library remains functional and widely used.

Q: Should I use web3.js or ethers.js for a new project? A: For new projects, ethers.js or Viem are generally recommended for their smaller bundle sizes and modern APIs. web3.js is a solid choice if your team already uses it or you rely on its plugin ecosystem.

Q: Does web3.js work with non-Ethereum chains? A: Yes. It works with any EVM-compatible chain (Polygon, BSC, Avalanche) by changing the provider URL.

Q: How do I handle contract events? A: Use contract.events.EventName() with a WebSocket provider to receive real-time event logs.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados