To call the contract method, you need to get the required transaction amount of energy and bandwidth.
How much energy and bandwidth is available in my account? link
//energy
currentAccountEnergy = EnergyLimit - EnergyUsed
//bandwidth
totalBandwidth = freeNetLimit + NetLimit;
totalBandwidthUsed = NetUsed + freeNetUsed;
currentAccountBandwidth = totalBandwidth - totalBandwidthUsed
how to calculate transaction bandwidth/energy?
for transfer Trx transfer and trc10, you need only bandwidth and for trc20 or smart contracts you need to pay for bandwidth and energy
calculate bandwidth
howManyBandwidthNeed = byte length of transaction protobuf + 64;
Refer to this book for how to create a tron transaction using Protobuf
If you use API to make a transaction, you can use the following formula to calculate the bandwidth,in some cases the value is slightly different 1-3 Bandwidth.
int howManyBandwidthNeed = transaction["raw_data_hex"].length;
for (String i in transaction["signatur"]) {
howManyBandwidthNeed += i.length;
}
howManyBandwidthNeed = (howManyBandwidthNeed / 2).round() + 68;
calculate energy
Receiving energy is specific to contracts and it is the same as
eth_estimateGas
in Ethereum, refer to this link
how much trx needs to burn for bandwidth?
If the required amount of bandwidth is less than the current bandwidth of your account, it will be deducted from the bandwidth of your account and is free, otherwise, the required amount will be multiplied by 1000.
how much trx needs to burn for energy?
The required energy is subtracted from the energy of your account and the remainder is multiplied by 420
this API got you current energy fee