web3-event-listener
v1.0.0
Published
A JavaScript package for listening to events emitted by smart contracts using Web3.
Downloads
2
Readme
Web3 Event Listener
A JavaScript package for listening to events emitted by smart contracts using Web3.
Installation
npm install web3-event-listener
Usage
const Web3EventListener = require('web3-event-listener');
const Web3 = require('web3');
// Initialize Web3 with the provider of your choice
const web3 = new Web3('http://localhost:8545');
// Specify the address of the smart contract you want to listen to events from
const contractAddress = '0x123456789abcdef...';
// Create a new instance of the Web3 Event Listener
const eventListener = new Web3EventListener(web3, contractAddress);
// Start listening for a specific event emitted by the contract
const eventName = 'Transfer'; // Example event name
eventListener.startListening(eventName, (eventData) => {
console.log('Received event data:', eventData);
// Perform actions based on the received event data
});
API
startListening(eventName, callback)
Starts listening for events emitted by the contract.
eventName
: The name of the event to listen for.callback
: A callback function to be invoked when an event is received. It receives the event data as an argument.
License
This project is licensed under the MIT License - see the LICENSE file for details.