Reputation: 41
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.
Upvotes: 4
Views: 3839
Reputation: 21
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,
……
}
Upvotes: 1
Reputation: 1137
I hope this isn't too late :)
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.
Upvotes: -1