Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

web3-core-subscriptions

Package Overview
Dependencies
Maintainers
4
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web3-core-subscriptions

Manages web3 subscriptions. This is an internal package.

  • 1.10.4
  • legacy
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
373K
increased by5.09%
Maintainers
4
Weekly downloads
 
Created

What is web3-core-subscriptions?

The web3-core-subscriptions package is part of the Web3.js library, which is used to interact with the Ethereum blockchain. This specific package provides functionality for subscribing to various events and data streams from the Ethereum network, such as new blocks, pending transactions, and logs.

What are web3-core-subscriptions's main functionalities?

Subscribe to New Blocks

This feature allows you to subscribe to new block headers on the Ethereum blockchain. The provided code sample demonstrates how to set up a subscription to new block headers using Web3.js and how to handle the incoming data.

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

const subscription = web3.eth.subscribe('newBlockHeaders', (error, result) => {
  if (!error) {
    console.log(result);
    return;
  }
  console.error(error);
});

// To unsubscribe
subscription.unsubscribe((error, success) => {
  if (success) {
    console.log('Successfully unsubscribed!');
  }
});

Subscribe to Pending Transactions

This feature allows you to subscribe to pending transactions on the Ethereum network. The code sample shows how to set up a subscription to pending transactions and handle the incoming transaction hashes.

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

const subscription = web3.eth.subscribe('pendingTransactions', (error, result) => {
  if (!error) {
    console.log(result);
    return;
  }
  console.error(error);
});

// To unsubscribe
subscription.unsubscribe((error, success) => {
  if (success) {
    console.log('Successfully unsubscribed!');
  }
});

Subscribe to Logs

This feature allows you to subscribe to logs (events) from smart contracts on the Ethereum blockchain. The code sample demonstrates how to set up a subscription to logs with specific options such as contract address and topics.

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

const options = {
  address: '0x123456...', // Address of the contract
  topics: ['0x123456...'] // Topics to subscribe to
};

const subscription = web3.eth.subscribe('logs', options, (error, result) => {
  if (!error) {
    console.log(result);
    return;
  }
  console.error(error);
});

// To unsubscribe
subscription.unsubscribe((error, success) => {
  if (success) {
    console.log('Successfully unsubscribed!');
  }
});

Other packages similar to web3-core-subscriptions

FAQs

Package last updated on 05 Feb 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc