Retrieve chain events

Each transaction emits events. At leastsystem.ExtrinsicSuccess or system.ExtrinsicFailed event will be returned for each transaction. These provide the overall execution result for the transaction, i.e. execution has succeeded or failed.

circle-info

If you are not familiar with the process of creating a transaction on the Ternoa chain, we highly suggest first reading the Getting Started section of the documentation with a focus on the Ternoa-js Blockchain Events section and the Workflow. Learn more about Events in the Polkadot's documentation. arrow-up-right

One of the main advantages of using the Ternoa-js SDK is that it handles and formats directly the transaction response for us.

Find the full events list here.

Methods

Several methods are offered from the generic class BlockchainEvents issued in each transaction response, to retrieve the specific events we can look for:

  • findEvent: to retrieve one specific kind of event.

  • findEvents: to retrieve several kinds of events.

  • findEventOrThrow: to retrieve a specific kind of event or throw an error.

Code available in the SDK repository herearrow-up-right.

Retrieving events using the BlockchainEvents class

Whether you are using the automated or custom way to create a transaction, it should be submitted using the submitTxBlocking() function. The response will include the following objects:

blockInfo,
events,
txHash,

The events object is the one containing all the transaction events list. Look at the code snippet in the Sign a transaction with Polkadot{.js} extension. You can see that the submitTxBlocking()is destructured to only get the events list on which the findEventOrThrow method is executed. It expects the name of the event for argument. Retrieve the complete events list here.

Last updated