Events

Effective integrations in your backend can be achieved using events, similar to how webhooks work. An event emitter will inform you about any events that could require actions to be performed like missing a block, saving you from repeatedly querying the API.

Emitting Events

Emitting events is pretty straightforward. Just resolve the event-emitter from @arkecosystem/core-container and call the emit method with a name and data to be emitted.

const container = require('@arkecosystem/core-container')
const emitter = container.resolvePlugin('event-emitter')

emitter.emit('block.forged', {
  id: 'fake-id',
  generatorPublicKey: 'fake-generator-public-key',
  amount: 10
})

Listening to Events

Listening to events is as straightforward as emitting them. Just resolve the event-emitter from @arkecosystem/core-container and call the on method with a name and then process the incoming data.

const container = require('@arkecosystem/core-container')
const emitter = container.resolvePlugin('event-emitter')

emitter.on('block.forged', block => {
  if (block.generatorPublicKey === 'fake-generator-public-key') {
    console.log(`You just forged a block for ${block.amount} ARK`)
  }
})

Available Events

block.applied

event

"block.applied"

description

Emitted when a block is applied to the Node and all including transactions are applied to wallets.

payload

Block

block.forged

event

"block.forged"

description

When a Delegate Node has created a new block, the newly created block is emitted.

payload

Block

block.reverted

event

"block.reverted"

description

Due to data corruption or other reasons, a Node might revert its state until it reaches a valid state. Blocks -including their transactions- are reverted from wallets.

payload

Block

delegate.registered

event

"delegate.registered"

description

When a transaction has been processed, and a wallet registers itself as a Delegate, the registered wallet is emitted.

payload

Delegate

delegate.resigned

event

"delegate.resigned"

description

This event will be emitted when a wallet resigns as a Delegate, and the transaction has been processed.

payload

Delegate

forger.failed

event

"forger.failed"

description

Emitted when the forger module fails to forge a new block.

payload

The error message causing the failure.

forger.missing

event

"forger.missing"

description

This event will be emitted when the forger is missing a block.

payload

The error message causing the failure.

forger.started

WARNING

This event is currently disabled to due to a bug in the implementation.

event

"forger.started"

description

When the forger module has started, this event is emitted.

payload

The publicKey of the forging Delegate.

peer.added

event

"peer.added"

description

This event will be emitted when a peer is added to the list of accepted peers.

payload

Peer

peer.removed

event

"peer.removed"

description

Fired after a peer has been removed from the accepted peers.

payload

Peer

transaction.applied

event

"transaction.applied"

description

This event will be emitted when a transaction is applied to a wallet.

payload

Transaction

transaction.expired

event

"transaction.expired"

description

After a transaction has expired and is removed from the transaction pool, the transactionGuard emits this event.

payload

Transaction

transaction.forged

event

"transaction.forged"

description

This event will be emitted when a transaction is included in a block and thus has been forged.

payload

Transaction

transaction.reverted

event

"transaction.reverted"

description

This event will be emitted when a transaction is reverted from a wallet. Often fired in conjunction with block.reverted.

payload

Transaction

wallet.vote

event

"wallet.vote"

description

This event will be emitted when a wallet casts a vote in on a delegate.

payload

Wallet

wallet.unvote

event

"wallet.unvote"

description

This event will be emitted when a wallet removes the vote for their current delegate.

payload

Wallet

Last Updated: 1/12/2019, 2:57:26 AM