Tronsave
🇬🇧 English
Search
K

Estimate energy

The method you must use to estimate energy of a request.
You can set any parameter like method.send()
To estimate a request, you can simply replace send() with estimateV2():
// Example method().send()
const onSend = async () => {
try {
const instance = await tronSave.contract().at("...");
const testSend = await instance.method().send({
feeLimit: 1e9,
callValue: 1000000,
...
})
} catch (err) {
console.log(err)
}
}
// With estimateV2()
const onEstimateEnergy = async () => {
try {
const instance = await tronSave.contract().at("...");
const testEstimateEnergy = await instance.method().estimateV2({
feeLimit: 1e9,
callValue: 1000000,
...
});
console.log(testEstimateEnergy);
// Response type: {
// available_energy: 0,
// discount_percent: 0,
// total_estimate_energy: 0,
// buy_energy_price: 0
// }
} catch (err) {
console.log(err)
}
}
Result estimateV2()
{
available_energy: 976304,
discount_percent: 80,
total_estimate_energy: 976304,
buy_energy_price: 65,
}
Keys
Type
Description
available_energy
number
The amount of energy that the system can provide for the above request. If it meets 100%, it will return the same amount of energy as estimated.
total_estimate_energy
number
The amount of energy that the system has estimated for the command.
buy_energy_price
number
It is the energy price (SUN) that you can buy the entire amount of energy estimated on the TRONSAVE market.