Jatin Sharma
Jatin Sharma

Reputation: 41

Find Tron Energy Estimate Before transaction?

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

Answers (2)

Alexandr  Nazarenko
Alexandr Nazarenko

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

Olamigoke Philip
Olamigoke Philip

Reputation: 1137

I hope this isn't too late :)

This documentation should cover your need i believe:

https://tronprotocol.github.io/documentation-en/mechanism-algorithm/resource/#2-how-to-set-fee-limit-caller-must-read

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

Related Questions