Event Subscription

Background

In version 3.5, the Tron development team provided event subscription mechanism, so developers can get events triggered on the chain by the event plugin.

Services

Tron provides the following ways to get events.

  1. TronGrid encapsulates the event plugin interface and provides a public, friendly https event query interface.
    https://developers.tron.network/reference/get-events-by-transaction-id
  2. TronWeb provides the encapsulated js methods to get events.
  3. Set up an event plugin locally to provide event queries.
  • The Tron development team released two event plug-ins,kafka & mongodb plug-ins.
  • Supporting subscription of chain data, such as block, transaction, contract log, contract event and so on,developers can also customize their own plug-ins according to their own needs.
  • Event query service tron-eventquery, online Event query service provided.

Plugin

The function of the plugin is to implement event dump. Developers can customize it according to their needs, such as Message queue, Kafka, MongoDB or writing to local files.

To use the event plugin, set useNativeQueue to false in the node configuration file, as follows:

event.subscribe = {
    native = {
      useNativeQueue = false // if true, use native message queue, else use event plugin.
      bindport = 5555 // bind port
      sendqueuelength = 1000 //max length of send queue
    }
   ...
}

The plugins provided by the Tron development team are independent of java-tron and is not loaded by default. It can be enabled by configuring command line parameters. By default, only subscriptions to smart contract event are supported. Developers could subscribe to other triggers by modifying configuration files,and developers are flexible in defining plug-in configuration files, including message queue server addresses, defined Trigger types, and so on.

Event Type

TRON Event Subscription supports 4 types of event:

1.Transaction Event
The parameters passed to Subscriber:

transactionId: transaction hash
blockHash: block hash
blockNumber: block number
energyUsage: energy usage
energyFee: energy fee
originEnergyUsage: origin energy usage  
energyUsageTotal: total energy usage total

2.Block Event
The parameters passed to Subscriber:

blockHash: block hash
blockNumber: block number
transactionSize: the number of transactions in a block
latestSolidifiedBlockNumber: the latest solidified block number
transactionList: the transactions hash list

3.Contract Event
The parameters passed to Subscriber:

transactionId: transaction id
contractAddress: contract address
callerAddress: contract caller address
blockNumber: the number of the block contract related events recorded
blockTimestamp: the block time stamp
eventSignature: event signature
topicMap: the map of topic in solidity language
data: the data information in solidity language
removed: 'true' means the log is removed

4.Contract Log Event
The parameters passed to Subscriber:

transactionId: transaction hash contractAddress: contract address
callerAddress: contract caller address
blockNumber: the number of the block contract related events recorded
blockTimestamp: the block time stamp
contractTopics: the list of topic in solidity language
data: the data information in solidity language
removed: 'true' means the log is removed

Contract Event and Contract Log Even support event filter function which includes:

fromBlock: the start block number
toBlock: the end block number
contractAddress: contract adsresses list
contractTopics: contract topics list

Note: History data query is not supported.
For more detailed information, please refer to the following url:
https://github.com/tronprotocol/TIPs/issues/12