post https://api.shasta.trongrid.io/wallet/triggerconstantcontract
Invoke the readonly function (modified by the view
or pure
modifier) of a contract for contract data query; or Invoke the non-readonly function of a contract for predicting whether the transaction can be successfully executed and estimating the energy consumption; or estimate the energy consumption of contract deployment
Note:
- TriggerConstantContract operation will not generate an on-chain transaction, nor will it change the status of the current node.
- For estimating energy
- To estimate the energy consumption of contract deployment just by passing the bytecode of contract through the
data
field - To estimate energy consumption of Contract Calls by calling non-read-only methods of contracts
- To estimate the energy consumption of contract deployment just by passing the bytecode of contract through the
- When using triggerconstantcontract to estimate energy consumption, the
energy_used
field in the returned value is the energy consumption. Therefore, thefee_limit
of the transaction can be set toenergy_used x energy unit price
. - Parameter encoding and decoding example: Parameter and return value encoding and decoding
Returns
Field | Type | Description |
---|---|---|
result | Return | Run result, for detailed parameter definition, refer to EstimateEnergy |
energy_used | int64 | Estimated energy consumption, including the basic energy consumption and penalty energy consumption |
energy_penalty | int64 | The penalty energy consumption |
constant_result | string[] | Result list |
transaction | Transaction | Transaction information, refer to GetTransactionByID |
Conclusion:
- The estimated energy consumption:
energy_used
- The penalty energy consumption:
energy_penalty
- The basic energy consumption:
energy_used
-energy_penalty