tronprotocol / tronweb

Javascript API Library for interacting with the TRON Network
MIT License
413 stars 271 forks source link

what is `energy_penalty` returned by triggerConstantContract? #483

Closed mattiaferrari02 closed 6 months ago

mattiaferrari02 commented 6 months ago

What is this data? Why isn't typed correctly in version 6.0.0-beta.1? How should I use it to calculate the fees for the execution of a smart contract?

start940315 commented 6 months ago

According to tron dev documentation, this data refer to the penalty energy consumption. We'll typed it in the next beta version.

mattiaferrari02 commented 6 months ago

so that is already counted in energy_used right?

start940315 commented 6 months ago

so that is already counted in energy_used right?

Yes!

mattiaferrari02 commented 6 months ago

Ok i also saw that here https://developers.tron.network/docs/resource-model#dynamic-energy-model and here https://medium.com/tronnetwork/introduction-to-dynamic-energy-model-31917419b61a the documentation talks about how to calculate accurately the energy used to call a smart contract during the current maintenance cycle. Firstly I noticed that tronweb seems to not support direclty /wallet/getcontractinfo endpoint. Then I needed an explanation on how to use the data returned from this endpoint to calculate accurately the energy to preview a transfer.

The endpoint returns

{"contract_state":{"update_cycle":6320,"energy_usage":7645965398,"energy_factor":12000} }  

for example using USDT mainnet token contract TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t

How can i transform this number 7645965398 to TRX? Is the energy_factor already counted in this number?

start940315 commented 6 months ago

energy_penalty is contained in energy_used field. You don't need to concern about the return of /wallet/getcontractinfo.