i want to calculate energy before transaction in tron blockchain, So we can show end users fees for transaction before transaction in app. But i am din't able to find any docs or any function any api for this. please help me in this.
Asked
Active
Viewed 879 times
2 Answers
0
Here is solution https://developers.tron.network/docs/set-feelimit#how-to-estimate-energy-consumption
An example is listed as follows:
$ curl -X POST https://nile.trongrid.io/wallet/triggerconstantcontract -d '{
"owner_address": "TTGhREx2pDSxFX555NWz1YwGpiBVPvQA7e",
"contract_address": "TVSvjZdyDSNocHm7dP3jvCmMNsCnMTPa5W",
"function_selector": "transfer(address,uint256)",
"parameter": "0000000000000000000000002ce5de57373427f799cc0a3dd03b841322514a8c00000000000000000000000000000000000000000000000000038d7ea4c68000",
"visible": true
}'
It returns:
{
……
"result": {
"result": true
},
"energy_used": 46236,
"energy_penalty": 32983,
……
}

ugexe
- 5,297
- 1
- 28
- 49

Alexandr Nazarenko
- 11
- 2
-1
I hope this isn't too late :)
This documentation should cover your need i believe:
Tron GET Endpoint: https://api.trongrid.io/v1/accounts/{contract}/transactions?only_confirmed=true
you may add &limit=
your preferred stop point [type=int e.g 200].
From the data returned you can get the energy_usage_total
for each then average it.
This gives insight into the energy consumed for the x numbers of latest transactions you requested for.

Olamigoke Philip
- 1,035
- 8
- 10
-
I'm still surprised this answer was initially downvoted. Here's a github gist implementing what i'd stated here: https://gist.github.com/andelf/65121c2c7f81e773f5f879d9992843f8 It's simple and straight forward enough: Get `energy_usage_total` for `x` numbers of transactions, average it, then convert it using the tron-energy price value. C'est fini – Olamigoke Philip Mar 17 '23 at 04:21
-
What is this user doesn't have the transactions yet? – deathangel908 Sep 01 '23 at 20:38
-
@deathangel908 I don't think it matters if a new wallet address has recorded a transaction or not. We are looking up the TRX contract directly to find `energy_usage_total` on the network – Olamigoke Philip Sep 02 '23 at 22:17