HomeGuidesAPI ReferenceChangelog
GuidesAPI ReferenceCommunityDiscordBlogFAQBug BountyAnnouncementsChange Log
Guides

TRC-20 Event Listener

Use Tronweb's watch method to listen to events emitted by the smart contract method. You can set a callback function to handle the event. When the event occurs, the callback function will be triggered. The following example listens to the transfer event of the TRC-20 contract.

Tronweb Example:

const privateKey = "..."; const trc20ContractAddress = "TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK" var address = "TM2TmqauSEiRf16CyFgzHV2BVxBejY9iyR"; let contract = await tronWeb.contract().at(trc20ContractAddress); //Use watch to listen for events emitted by a smart contract method. You can define functions to be executed when certain events are caught. let tx = contract.transfer("TVDGpn4hCSzJ5nkHPLetk8KQBtwaTppnkr", 1000000).send().then(output => {console.log('- Output:', output, '\n');}); //contract.eventname.watch(callback) await contract && contract.Transfer().watch((err, event) => { if(err) return console.error('Error with "Message" event:', err); console.group('New event received'); console.log('- Contract Address:', event.contract); console.log('- Event Name:', event.name); console.log('- Transaction:', event.transaction); console.log('- Block number:', event.block); console.log('- Result:', event.result, '\n'); console.groupEnd(); });