v4 is here! Read all about it

Build dApps on any EVM Chain with TypeScript Libraries

npm i web3
ChainSafe Logo, maintainer of web3js

Maintained by ChainSafe

Abstract pattern of gemoetric shapes

Trusted by

Ethereum
Zksync
Chainlink
Chainstack
ENS
Near
Optimism

Why Web3.js?

Web3.js was established in 2014, making it the oldest web3 library. With extensive documentation, an active community and modular design, Web3.js is powerful and easy-to-use.

2M

Monthly npm usage

2M

Monthly CDN requests

500k

Weekly downloads

19K

GitHub stars

3K+

Dependent projects

With Web3.js, you can

Deploy and interact with smart contracts as TS/JS objects.

Subscribe to specific on-chain or smart contract events

Interact with the Ethereum Name Service (ENS)

Create and import accounts, sign data and transactions.

Get block and state information from Ethereum nodes.

Have access to utilities with built-in helpers for Ethereum dApps and web3 packages

Web3.js Features

Abstractions over the JSON-RPC API

Simplifying interaction for your Developer Experience.

Dynamic contract types and full API in TypeScript

Enforced with strict types for enhanced security and safety.

Most efficient ABI Encoder & Decoder

Include only what you need during bundling for optimized performance.

ESM and CJS module builds

Support for both ECMAScript module and CommonJS module builds for flexible integration with various project setups.

Custom Output formatters

Format any returned value to be a string, number, BigInt, etc., providing flexibility in handling output data.

Language Aligned

to the official Ethereum terminology

Web3js Ambassadors

Why be an ambassador

Exclusive access

to the web3.js core development team.

Get support

expanding your local meetup community.

Shape community

-driven initiatives within the web3.js ecosystem.

Network and make connections

with like-minded ambassadors.

Boost your work

through our social media and online platforms.

Advance your career

and establish yourself as a leader in blockchain technology.

Build your personal brand

through content creation and speaking opportunities.

Step 1. Import Web3 module.

import {Web3} from "web3"; // set a provider in the sepolia testnet using node rpc url const web3 = new Web3("https://rpc.sepolia.org"); // interacting with the smart contract const abi = [ { outputs: [ { internalType: "uint256", name: "randomNo", type: "uint256", }, ], name: "generateRandomNumber", stateMutability: "nonpayable", type: "function", }, ] as const; const address = "0xA36432F7B12f160F685717c4Ab12EB883a682810"; // create a new contract object, providing the ABI and address const contract = new web3.eth.Contract(abi, address); // using contract.methods to get value contract.methods .generateRandomNumber() .call() .then(console.log);

Step 2. Initialize a Web3 provider.

import {Web3} from "web3"; // set a provider to the sepolia testner using node rpc url const web3 = new Web3("wss://sepolia.infura.io/ws/v3/API_KEY"); // interacting with the smart contract const abi = [ { inputs: [ { internalType: "uint256", name: "randomNo", type: "uint256", }, ], name: "RandomNo", type: "event", }, ] as const; const address = "0xA36432F7B12f160F685717c4Ab12EB883a682810"; // create a new contract object, providing the ABI and address const contract = new web3.eth.Contract(abi, address); // using contract.methods to get value const subscription = contract.events.RandomNo() subscription.on("data", console.log); // new value every time the event is emitted

Step 3. Start querying; i.e, current block number.

import {Web3} from "web3" // set a provider such as using infura const web3 = new Web3("https://rpc.sepolia.org") // Get the balance of an Ethereum address web3.eth.getBalance("0xF8561Dc64E577B0CF53dd3FC11329e80B1A8343e").then(console.log) // result: 1.000.000 eth // Get the latest block number web3.eth.getBlockNumber().then(console.log) // result: BigInt(xxx)

Testimonials

“At Chainstack, Web3.js has been instrumental in developing our RPC API documentation and tutorials. Its robust features and seamless integration allow us to showcase use cases effectively, enabling developers to leverage the full potential of blockchain technology quickly. Web3.js is a foundational tool that enhances our ability to support developers in building scalable and innovative applications on multiple blockchains.”

web3js testimonial0

“Developing the Namespace ENS plugin for Web3.js was a smooth experience. Developer docs are concise and easy to follow, and their SDK made the process even more frictionless. On top of that, the DevRel team was always available to provide any support if needed.”

web3js testimonial1

“We have been relying on Web3.js to build DeFi Saver since 2020. With us having built a lot of custom infra in-house, Web3.js had been a great tool for this purpose. The API has been stable and it provided us enough visibility and control over the entire stack. It has also been here for a while and all the tooling around it is stable and ready, so theres hardly ever any issues.”

web3js testimonial2