Socket
Socket
Sign inDemoInstall

web3

Package Overview
Dependencies
0
Maintainers
4
Versions
467
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    web3

Ethereum JavaScript API


Version published
Maintainers
4
Created

Package description

What is web3?

The web3 npm package is a collection of libraries that allow you to interact with a local or remote Ethereum node, using HTTP, IPC, or WebSocket. It provides functionalities for interacting with smart contracts, sending transactions, and querying blockchain data.

What are web3's main functionalities?

Connecting to an Ethereum Node

This feature allows you to connect to an Ethereum node using an HTTP provider. You can replace the URL with your own node's URL or use a service like Infura.

const Web3 = require('web3');
const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');

Interacting with Smart Contracts

This feature allows you to interact with smart contracts deployed on the Ethereum blockchain. You need the contract's ABI and address to create a contract instance and call its methods.

const contractABI = [/* ABI array */];
const contractAddress = '0xYourContractAddress';
const contract = new web3.eth.Contract(contractABI, contractAddress);
contract.methods.yourMethod().call().then(console.log);

Sending Transactions

This feature allows you to send transactions on the Ethereum network. You need the sender's account address and private key to sign and send the transaction.

const account = '0xYourAccountAddress';
const privateKey = 'your_private_key';
const tx = {
  to: '0xRecipientAddress',
  value: web3.utils.toWei('0.1', 'ether'),
  gas: 2000000
};
web3.eth.accounts.signTransaction(tx, privateKey).then(signed => {
  web3.eth.sendSignedTransaction(signed.rawTransaction)
    .on('receipt', console.log);
});

Querying Blockchain Data

This feature allows you to query data from the blockchain, such as retrieving the latest block information.

web3.eth.getBlock('latest').then(console.log);

Other packages similar to web3

Readme

Source

web3.js

web3.js

ES Version Node Version NPM Package Downloads

This is the main package of web3.js, it contains a collection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.

Features

  • Web3.js Plugins🧩: Enhance or add any functionality by creating scalable web3 plugins for any project.
  • Abstractions over the JSON-RPC API: Simplifying interaction for your Developer Experience.
  • Language aligned to the official Ethereum terminology
  • Tree-shaking focus: Include only what you need during bundling for optimized performance.
  • Dynamic contract types and full API in TypeScript: Enforced with strict types for enhanced security and safety.
  • Complete utilities and functionalities for all your Ethereum needs
  • More efficient ABI Encoder & Decoder
  • Extensive documentation with guides and APIs
  • Large collection of test cases
  • First-class APIs for interacting with Smart Contracts
  • ESM and CJS module builds: Support for both ECMAScript module and CommonJS module builds for flexible integration with various project setups.
  • Contracts dynamic types & full API in TypeScript
  • Using native BigInt instead of large BigNumber libraries: Use native BigInt for improved efficiency compared to using large external BigNumber libraries.
  • Custom Output formatters: Format any returned value to be a string, number, BigInt, etc., providing flexibility in handling output data.

Installation

You can install the package either using NPM or using Yarn

Using NPM

npm install web3

Using Yarn

yarn add web3

Getting Started

Prerequisites

Migration Guide

  • Migration Guide from Web3.js 1.x to 4.x Breaking changes are listed in migration guide and its first step for migrating from Web3.js 1.x to 4.x. If there is any question or discussion feel free to ask in discord, and in case of any bug or new feature request open issue or create a pull request for contributions.

Package.json Scripts

ScriptDescription
cleanUses rimraf to remove dist/
buildUses tsc to build package and dependent packages
lintUses eslint to lint package
lint:fixUses eslint to check and fix any warnings
formatUses prettier to format the code
testUses jest to run unit tests
test:integrationUses jest to run tests under /test/integration
test:unitUses jest to run tests under /test/unit

Web3.js Packages

We encourage users to use only required individual packages listed in following table, for making lightweight application instead of importing main web3 package, and if you don't need functions from most of the packages that are implicitly included with main web3 package.

PackageVersionLicenseDocsDescription
web3npmLicense: LGPL v3documentation:rotating_light: Entire Web3.js offering (includes all packages)
web3-corenpmLicense: LGPL v3documentationCore functions for web3.js packages
web3-errorsnpmLicense: LGPL v3documentationErrors Objects
web3-ethnpmLicense: LGPL v3documentationModules to interact with the Ethereum blockchain and smart contracts
web3-eth-abinpmLicense: LGPL v3documentationFunctions for encoding and decoding EVM in/output
web3-eth-accountsnpmLicense: LGPL v3documentationFunctions for managing Ethereum accounts and signing
web3-eth-contractnpmLicense: LGPL v3documentationThe contract package contained in web3-eth
web3-eth-ensnpmLicense: LGPL v3documentationFunctions for interacting with the Ethereum Name Service
web3-eth-ibannpmLicense: LGPL v3documentationFunctionality for converting Ethereum addressed to IBAN addressed and vice versa
web3-eth-personalnpmLicense: LGPL v3documentationModule to interact with the Ethereum blockchain accounts stored in the node
web3-netnpmLicense: LGPL v3documentationFunctions to interact with an Ethereum node's network properties
web3-providers-httpnpmLicense: LGPL v3documentationWeb3.js provider for the HTTP protocol
web3-providers-ipcnpmLicense: LGPL v3documentationWeb3.js provider for IPC
web3-providers-wsnpmLicense: LGPL v3documentationWeb3.js provider for the Websocket protocol
web3-rpc-methodsnpmLicense: LGPL v3documentationRPC Methods
web3-typesnpmLicense: LGPL v3documentationShared useable types
web3-utilsnpmLicense: LGPL v3documentationUseful utility functions for Dapp developers
web3-validatornpmLicense: LGPL v3documentationUtilities for validating objects

Keywords

FAQs

Last updated on 06 May 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc