I want to track transactions on the Tron blockchain network. More precisely, I want to follow the transactions made through my own address, but I could not find any way. I tried the following way but it says "subscribe" method is an undefined method. I found some content about Websocket I got Websocket API via QuickNode but it didn't work either. Is there a way I can track transactions on the Tron network? But I don't want to do this by constantly making HTTP requests. I want to be notified when there is a transaction.
I tried the code below and the Websocket method, but no results.
this.web3 = new TronWeb({
fullHost: this.network.host,
solidityNode: this.network.host,
eventServer: this.network.event,
});
this.web3.eventServer.subscribe('transactions', (error, event) => {
if (error) {
console.error('Error subscribing to transaction event:', error);
} else {
console.log('New transaction:', event);
}
});
This was a major shortcoming for the Tron Blockchain network and there was no easy solution. The only way was to build your own full node, which was a really costly process both in time and money. Based on the problem I had here, I created TronSocket.com and now listening to Tron Blockchain events is a piece of cake, as in the example below.
import TronSocket, { Transaction } from "@tronsocket/sdk/node";
const socket = new TronSocket("your_token_here");
await socket.connect().then((connected) => {
console.log("Connected:", connected);
}).catch((error) => {
console.error("Error:", error);
});
// All transactions
socket.on("transaction", (tx: Transaction) => {
const id = tx.transactionId;
});
const usdtAddress = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'
// Only USDT transactions
socket.on("transaction", (tx: Transaction) => {
const id = tx.transactionId;
}, { toAddress: usdtAddress });