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.

This method will use 30 Compute Units.


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

  • When using triggerconstantcontract to estimate energy consumption, the energy_used field in the returned value is the energy consumption. Therefore, the fee_limit of the transaction can be set to energy_used x energy unit price.

  • Parameter encoding and decoding example: Parameter and return value encoding and decoding

Parameters

  • owner_address - String - Owner address that triggers the contract. If visible=true, use base58check format, otherwise use hex format. For constant call you can use the all-zero address.

  • contract_address - String - Smart contract address. If visible=true, use base58check format, otherwise use hex format

  • function_selector - String - Function call, must not be left blank

  • parameter - String - Parameter encoding needs to be in accordance with the ABI rules, the rules are more complicated, users can use the ethers library to encode,For details, please refer to the document-Guide-Smart Contract-Best Practice-Parameter Encoding and Decoding.

  • data - String - The data for interacting with smart contracts, including the contract function and parameters. You can choose to use this field, or you can choose to use function_selector and parameter for contract interaction. When both of data and function_selector exist, function_selector is preferred

  • call_value - int64 - Amount of TRX transferred to the contract with this transaction, the unit is sun. This field may be used when estimating energy consumption

  • call_token_value - int64 - Amount of TRC10 token transferred with this transaction

  • token_id - int64 - TRC10 token id

  • visible - boolean - Optional. Specifies whether the address is in Base58 format (default: false)

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

Last updated

Was this helpful?