Skip to content

Instantly share code, notes, and snippets.

@gabmontes
Last active July 18, 2021 09:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gabmontes/8bcce5694bf838324f79a2e4c1320346 to your computer and use it in GitHub Desktop.
Save gabmontes/8bcce5694bf838324f79a2e4c1320346 to your computer and use it in GitHub Desktop.
Very simple example of an ERC20 token events listener
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...')
{
"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