How to get all events logs of the contract in tron network using tronweb in node js without any limit? or is there need of any middle ware storage like redis, etc? Need to get all data at once before loading dapp home page. The dApp is made in react js. And Trongrid api have this limit of 200 records in single request.
Asked
Active
Viewed 4,512 times
0
-
1Is there any overall limit in tronweb of nearly 10,000 requests? – Manish Sharma Jan 06 '21 at 05:11
1 Answers
5
You can use fingerprint
(it works like continue token)
async getContractTransferEventsByUser(eventName, userId) {
let result = [];
let tronGrid = new TronGrid(this.tronWeb);
try {
let continueToken = '';
while (true) {
let res = await tronGrid.contract.getEvents(YOUR_CONTRACT_ADDRESS, {
only_confirmed: true,
event_name: eventName,
limit: 200,
fingerprint: continueToken,
order_by: "timestamp,asc",
min_timestamp: minTime, //remove if you don't need it
filters: { id: userId.toString() } //if you need to filter events by one or more values, for example, by user id (if this information is presented in event log), remove if you don't need it.
});
if (!res.success) {
console.warn("Can't get events for the contract");
break;
}
result = result.concat(res.data);
if (typeof res.meta.fingerprint !== 'undefined') {
continueToken = res.meta.fingerprint;
} else {
break;
}
}
} catch (error) {
console.error(error);
} finally {
return result;
}
},

JeyMcKey
- 86
- 5
-
2
-
2This seems not working now. I always get, 'Exceeds the maximum limit, please change your query time range'' error – Yogesh - EtherAuthority.io Dec 07 '20 at 16:55
-
1
-
One way is to break fingerprint request with some limit on event, to solve maximum limit issue, but still looking for better solution – Manish Sharma Jan 13 '21 at 12:46
-
1get all events from contract with each transaction of the contract, it is better solution for limit issues – Manish Sharma May 05 '21 at 04:17
-
In the response, i got "from" and "to" address looking like ethereum address instead of trc20 address hex format. How do i go about converting this "0x" address to something more familliar please? – Ola Fashade Samson Jun 07 '21 at 15:07