Last active
July 18, 2021 09:10
-
-
Save gabmontes/8bcce5694bf838324f79a2e4c1320346 to your computer and use it in GitHub Desktop.
Very simple example of an ERC20 token events listener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3') | |
const erc20Abi = abi = require('human-standard-token-abi') | |
const config = { | |
node: 'localhost:8546', | |
address: '0x0000000000000000000000000000000000000000' // set to contract address | |
} | |
const provider = new Web3.providers.WebsocketProvider(`ws://${config.node}`) | |
const web3 = new Web3(provider) | |
const contract = new web3.eth.Contract(erc20Abi, config.address); | |
contract.events.allEvents(function (err, event) { | |
if (err) { | |
console.error('Error', err) | |
process.exit(1) | |
} | |
console.log('Event', event) | |
}) | |
console.log('Waiting for events...') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"human-standard-token-abi": "^1.0.2", | |
"web3": "^1.0.0-beta.24" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment