Skip to content

Latest commit

 

History

History
71 lines (54 loc) · 2.14 KB

NEON-EVENT-LISTENER.md

File metadata and controls

71 lines (54 loc) · 2.14 KB

NeonEventListener

Initialize NeonEventListener

To use NeonEventListener you can simply call its constructor passing the network you want to use.

import { NeonEventListener } from '@cityofzion/neon-dappkit'
import { default as Neon } from '@cityofzion/neon-js'

const eventListener = new NeonEventListener(NeonEventListener.MAINNET)

You can also pass a custom RPC endpoint:

const eventListener = new NeonEventListener('http://127.0.0.1:5001')

Usage

Listen to an event on the blockchain

Everytime the specified event is triggered, the callback will be called

const contract = '0x123456'
const eventname = 'Transfer'
const callback = (event) => {
    console.log(event)
}

eventListener.addEventListener(contract, eventname, callback)

Remove an event listener

Use this method to unsubscribe from the event, avoiding memory leaks

eventListener.removeEventListener(contract, eventname, callback)

You can also use the method removeAllEventListenersOfContract or removeAllEventListenersOfEvent.

Wait for a transaction to be completed and confirm it was successful

On the following example we are waiting for a transaction to be completed, and then we are only confirming it has the HALT state.

const appLog = await eventListener.waitForApplicationLog(transactionId)

eventListener.confirmTransaction(appLog)

You can also confirm the transaction has a specific event, and if the return value of the transaction is true with the following optional parameters:

const appLog = await eventListener.waitForApplicationLog(transactionId)

const eventToCheck = {
    contract: '0x123456',
    eventname: 'Transfer'
}
const confirmStackTrue = true
eventListener.confirmTransaction(
    appLog,
    eventToCheck,
    confirmStackTrue)

More Details

For more details on the methods signature, check the auto-generated Docs and the Source Code.