tronprotocol / tronweb

Javascript API Library for interacting with the TRON Network
MIT License
383 stars 258 forks source link

How to actually calculate the amount of resources for a transaction? #512

Open itxtoledo opened 2 months ago

itxtoledo commented 2 months ago

I've already tried to get the energy and bandwidth prices from the library functions but they always return values ​​that don't seem to make any sense, like 420 for 1 energy (what does that mean?).

How to actually calculate the cost of energy and bandwidth needed so that I don't receive errors like send:BANDWITH_ERROR?

laurenceja commented 2 months ago

I've already tried to get the energy and bandwidth prices from the library functions but they always return values ​​that don't seem to make any sense, like 420 for 1 energy (what does that mean?).

The energy unit price is 420 sun.

How to actually calculate the cost of energy and bandwidth needed so that I don't receive errors like send:BANDWITH_ERROR?

Here is a guide about how to estimate energy/bandwidth consumption of a transaction.

itxtoledo commented 2 months ago

Okay converting resources needed to transfer TRX:

bandwidth: 266 sun bandwidth price: 1000 sun

Total: 266000 sun or 0.266 TRX

And how to calculate in TRX if i dont have bandwidth or energy?

laurenceja commented 2 months ago

Okay converting resources needed to transfer TRX:

bandwidth: 266 sun bandwidth price: 1000 sun

Total: 266000 sun or 0.266 TRX

And how to calculate in TRX if i dont have bandwidth or energy?

  1. Estimate the bandwidth and energy consumption according to this guide. Assume the transaction will need A bandwidth and B energy.
  2. Set the feelimit of the transaction to B*420 or more than to this value. (The energy unit price is 420 sun)
  3. Ensure the account has enough TRX to pay for the energy and bandwidth fee. Assume the account has no bandwidth and energy. at this situation, the account's TRX balance must be at least A1000+B420 sun.
itxtoledo commented 2 months ago

thank you

itxtoledo commented 1 month ago

According to this transaction, the real price of energy would be 0.0797 TRX, how did the value of 420 become this? https://tronscan.org/#/transaction/a66fc4ad2f3390cf605f99512c3b002a3354ea74d761fc803c454246cebcfa40

ferdinand026 commented 1 month ago

According to this transaction, the real price of energy would be 0.0797 TRX, how did the value of 420 become this? https://tronscan.org/#/transaction/a66fc4ad2f3390cf605f99512c3b002a3354ea74d761fc803c454246cebcfa40

You confused two concepts, one is the energy unit price, the other is the energy resource share.

  1. energy unit price It's about transaction fees. It is the NO.11parameter of the tron network, the fee of 1 unit of Energy, now the value is 420sun (0.00042 TRX). You can view it on tronscan: https://tronscan.org/#/sr/committee For example, if a transaction needs to consume X amount of energy and the account has no energy, then the account needs to pay for a fee of X*0.00042 TRX for energy consumption.

  2. energy resource share Resource share is a measure of the user’s ability to obtain resources from the network resource pool. The TRON network supplies a fixed amount of bandwidth and energy resources every day and allocates resources to users according to the proportion of TRX staked by users. The amount of TRX staked by users to obtain energy/bandwidth resources is the energy/bandwidth resource share. For more detailed information, you can get from here: https://developers.tron.network/docs/resource-model

    Energy amount = (energy share / TRX staked for energy in total )* energy supplied in the whole network

    So for the delegate energy transaction, in fact it is to delegate how much amount of energy resource share to target address, and the target address will receive the amount of energy corresponding to the energy share.

    The transaction you provided is to delegate energy resource share of 755.864975 TRX to destination address:TAJpAf3ZitrUu5NnRjhvHmeKpJfuGrV6kV , and according to the above formula, the destination address will receive about 9400 energy. because the TRX staked for energy in total is changed all the time, so the energy received by the target address also changes in real time.