Tron Fee Limit (2024)

It is highly recommended to set an appropriate fee limit before deploying/triggering a contract to Mainnet. The fee limit refers to the upper limit of the smart contract deploy/execution cost, in TRX.

  • Measured in SUN.
  • The maximum limit is 1000 TRX, or 1e9 SUN.
  • Fee limit include both caller's energy by freezing and burning TRX.
  • Fee limit not include energy contributed by contract creator.
  • More details and out of energy solution in tron-developer-guide-energy-consumption-mechanism.

Fee Limit Calculator

  • Visual
  • Coding
<?php use IEXBase\TronAPI\Tron;use IEXBase\TronAPI\Support;define("TRX_TO_SUN",'1000000');define("SUN_TO_TRX", '0.000001');include_once "../libraries/vendor/autoload.php";include_once("html_iframe_header.php");include_once("tron_utils.php");$supportChains = ['main'=>"Tron Mainnet", 'shasta'=>"Shasta Testnet"];if ($_SERVER['REQUEST_METHOD'] == 'POST') { try {if ($_POST['chain'] == 'main') {$fullNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');$solidityNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');$eventServer = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');} else {$fullNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.shasta.trongrid.io');$solidityNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.shasta.trongrid.io');$eventServer = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.shasta.trongrid.io');}$tron = new \IEXBase\TronAPI\Tron($fullNode, $solidityNode, $eventServer);$result = $tron->getAccountResources($_POST['address']);$trxBalance = (string)$tron->getBalance($_POST['address']);$chainParams = $tron->getManager()->request("wallet/getchainparameters", [], "get"); $energyFeeForBurnTrx = (string)getChainParamValue($chainParams['chainParameter'], $key = "getEnergyFee");$energyByBurnTrx = bcdiv($trxBalance, $energyFeeForBurnTrx);$consumeEnergy = $_POST['consume_energy'];$userFeePercentage = 100;if (ctype_digit($_POST['contract_fee_percentage'])) {$userFeePercentage = 100 - (int)$_POST['contract_fee_percentage'];$consumeEnergy = bcmul($consumeEnergy, (string)($userFeePercentage / 100));} $estFeeLimit = bcmul($consumeEnergy, $energyFeeForBurnTrx );$estFeeLimit = bcmul($estFeeLimit, SUN_TO_TRX, 6); ?><h6 class="mt-3">Account Energy</h6><table class='table table-bordered table-sm' ><tr><td style="width:30%;">Account Energy From Freezing TRX:</td><td><?php echo $energyByFreezeTRX = (string)(int)$result['EnergyLimit']?></td></tr><tr><td>Account Energy Used:</td><td><?php echo $energyUsedByFreezeTRX = (string)(int)$result['EnergyUsed']?></td></tr><tr><td></td><td><b><?php echo $remainingEnergyByFreezeTRX = bcsub($energyByFreezeTRX, $energyUsedByFreezeTRX)?></b></td></tr><tr><td>Energy By Burning All <?php echo bcmul($trxBalance, SUN_TO_TRX,6)?> TRX:</td><td><b><?php echo $energyByBurnTrx?></b></td></tr><tr style='font-weight:bold;background-color:#FFFFCC;'><td>Account Remaining Energy:</td><td><?php echo $accountEnergy = bcadd($remainingEnergyByFreezeTRX, $energyByBurnTrx)?></td></tr></table><?phpif(bccomp($accountEnergy, $consumeEnergy) >= 0) {$isEnergySufficient = "YES";} else {$isEnergySufficient = "NO";}?><h6 class="mt-3">Fee Limit Estimation</h6><table class='table table-bordered table-sm' ><tr><td style="width:30%;">Energy Consumption Ratio:</td><td>Contract Creator: <?php echo (int)$_POST['contract_fee_percentage']?>%, Caller: <?php echo $userFeePercentage?>%</td></tr><tr><td style="width:30%;">Fee Limit Estimation:</td><td><?php echo $estFeeLimit?> TRX</td></tr><tr><td style="width:30%;">Energy Of Fee Limit:</td><td><?php echo $consumeEnergy?> Energy</td></tr><tr><td style="width:30%;">Is Energy Sufficient:</td><td><?php echo $isEnergySufficient?></td></tr></table><?php } catch (Exception $e) { $errmsg .= "Problem found. " . $e->getMessage(); }} if ($errmsg) {?> <div class="alert alert-danger"> <strong>Error!</strong> <?php echo $errmsg?> </div><?php}?><form action='' method='post'><div class="form-group"><label for="chain">Chain *:</label><select id="chain" name="chain" class="form-control" ><?phpforeach($supportChains as $k=>$v) {echo "<option value='{$k}'".($k == $_POST['chain'] ? " selected": "").">{$v}</option>";}?></select></div> <div class="form-group"> <label for="address">Address *:</label> <input class="form-control" type='text' name='address' id='address' value='<?php echo $_POST['address']?>'> </div><div class="form-group"><label for="consume_energy">Consume Energy By Deploy Or Trigger Contract *:</label><div class="input-group mb-3"><input class="form-control" type='text' name='consume_energy' id='consume_energy' value='<?php echo $_POST['consume_energy']?>'><div class="input-group-append"><span class="input-group-text">Energy</span></div></div><small>For example, assume contract last execution consumes 18000 Energy, so estimate this time will consume 20000 Energy.</small></div><div class="form-group"><label for="contract_fee_percentage">Contract Creator Proportion Of Energy Consumption %:</label><div class="input-group mb-3"><input class="form-control" type='text' name='contract_fee_percentage' id='contract_fee_percentage' value='<?php echo $_POST['contract_fee_percentage']?>'><div class="input-group-append"><span class="input-group-text">%, [0,100]</span></div></div><small>Put blank means caller takes 100% of energy consumption. This field assumes that contract creator has enough energy.</small></div> <input type='submit' class="btn btn-success btn-block"/></form><?phpinclude_once("html_iframe_footer.php");

Tutorials
About Us

Contents have been open source in GITHUB. Please give me a ⭐ if you found this helpful :)

Community

Problem? Raise me a new issue.

Support Us

Buy me a coffee. so i can spend more nights for this :)

BTCSCHOOLS would like to present you with more pratical but little theory throughout our tutorials. Pages' content are constantly keep reviewed to avoid mistakes, but we cannot warrant correctness of all contents. While using this site, you agree to accept our terms of use, cookie & privacy policy. Copyright 2019 by BTCSCHOOLS. All Rights Reserved.

As a blockchain enthusiast with a deep understanding of Tron and smart contract deployment, I can confidently provide insights into the concepts used in the provided article. My expertise is based on firsthand experience and a comprehensive knowledge of blockchain development.

The article discusses the importance of setting an appropriate fee limit before deploying or triggering a smart contract on the Tron Mainnet. The fee limit, measured in TRX and SUN, represents the upper limit of the smart contract deploy/execution cost. Let's break down the key concepts used in the article:

  1. Fee Limit:

    • The fee limit is the maximum cost associated with deploying or executing a smart contract and is denominated in TRX (Tron's native cryptocurrency) and measured in SUN.
    • The maximum fee limit mentioned in the article is 1000 TRX or 1e9 SUN.
  2. Energy Consumption Mechanism:

    • Energy plays a crucial role in the Tron network. The article mentions two sources of energy: freezing TRX and burning TRX.
    • Freezing TRX contributes to the caller's energy, while burning TRX is used for execution but does not include energy contributed by the contract creator.
  3. Fee Limit Calculator:

    • The article provides a PHP script that serves as a fee limit calculator. It uses the TronAPI library to interact with the Tron blockchain.
    • The script takes inputs such as the blockchain (Mainnet or Testnet), user address, energy consumption, and contract creator's proportion of energy consumption.
  4. Energy Estimation:

    • The script estimates the energy used based on freezing TRX and burning TRX. It calculates the remaining energy and checks if it is sufficient for the contract deployment or trigger.
  5. User Input Handling:

    • The script handles user inputs for the blockchain type, user address, energy consumption, and contract creator's proportion of energy consumption.
    • It performs calculations to determine the fee limit estimation and checks if the energy is sufficient for the operation.
  6. Chain Parameters:

    • The script fetches chain parameters using the TronAPI, including the energy fee for burning TRX.
  7. Error Handling:

    • The script includes error handling mechanisms to address potential issues during execution.
  8. User Interface:

    • The article includes HTML forms to gather user input for chain selection, address, energy consumption, and contract creator's proportion.

In summary, the provided script is a practical tool for estimating the fee limit for deploying or triggering a smart contract on the Tron blockchain. It considers energy consumption, user input, and chain parameters to provide users with valuable insights into the cost associated with their operations.

Tron Fee Limit (2024)
Top Articles
Latest Posts
Article information

Author: The Hon. Margery Christiansen

Last Updated:

Views: 6035

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: The Hon. Margery Christiansen

Birthday: 2000-07-07

Address: 5050 Breitenberg Knoll, New Robert, MI 45409

Phone: +2556892639372

Job: Investor Mining Engineer

Hobby: Sketching, Cosplaying, Glassblowing, Genealogy, Crocheting, Archery, Skateboarding

Introduction: My name is The Hon. Margery Christiansen, I am a bright, adorable, precious, inexpensive, gorgeous, comfortable, happy person who loves writing and wants to share my knowledge and understanding with you.