跳至主要內容

Smart Contracts

tokenview大约 5 分钟

Smart Contracts

getcontract

POST https://services.tokenview.io/vipapi/nodeservice/trx/wallet/getcontract?apikey={apikey}

Queries a contract's information from the blockchain, including the
bytecode of the contract, ABI, configuration parameters, etc.

请求参数说明:

  • value: string. Contract address, converted to a hex string.
  • visible: boolean. Optional, is address in visible format(base58check) or hex?

Request

curl --location -g 'https://services.tokenview.io/vipapi/nodeservice/trx/wallet/getcontract?apikey={apikey}' \
--data '{
  "value": "411584F89A01DC693A8ABEF18F426D91A6D4592AB7",
  "visible": false
}'

Response


getcontractinfo

POST https://services.tokenview.io/vipapi/nodeservice/trx/wallet/getcontractinfo?apikey={apikey}

Queries a contract's information from the blockchain. The difference from the wallet/getcontract interface is that this interface returns not only the bytecode but also the runtime bytecode of the contract. Compared with bytecode, runtime bytecode does not contain constructor and constructor parameter information.

Parameters:

  • value: string. Contract address, converted to a hex string.
  • visible: boolean. Optional, is address in visible format(base58check) or hex?

Request

curl --location -g 'https://services.tokenview.io/vipapi/nodeservice/trx/wallet/getcontractinfo?apikey={apikey}' \
--data '{
  "value": "411584F89A01DC693A8ABEF18F426D91A6D4592AB7",
  "visible": false
}'

Response


triggersmartcontract

POST https://services.tokenview.io/vipapi/nodeservice/trx/wallet/triggersmartcontract?apikey={apikey}

Returns TransactionExtention, which contains the unsigned Transaction.

Note:
ABI rulesopen in new window

Example: Parameter and return value encoding and decodingopen in new window

请求参数说明:

  • owner_address: string. Address that triggers the contract, converted to a hex string.
  • contract_address: string. Contract address, converted to a hex string
  • 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.
  • fee_limit: int32. Maximum TRX consumption, measured in SUN (1 TRX = 1,000,000 SUN).
  • call_value: int32. Amount of TRX transferred with this transaction, measured in SUN (1 TRX = 1,000,000 SUN).
  • permission_id: int32. Optional, for multi-signature
  • visible: boolean. Optional. Whehter the address is in base58check format.

Request

curl --location -g 'https://services.tokenview.io/vipapi/nodeservice/trx/wallet/triggersmartcontract?apikey={apikey}' \
--data '{
  "owner_address": "41D1E7A6BC354106CB410E65FF8B181C600FF14292",
  "contract_address": "41a7837ce56da0cbb28f30bcd5bff01d4fe7e4c6e3",
  "function_selector": "transfer(address,uint256)",
  "parameter": "string",
  "fee_limit": 0,
  "call_value": 0,
  "permission_id": 0,
  "visible": true
}'

Response


triggerconstantcontract

POST https://services.tokenview.io/vipapi/nodeservice/trx/wallet/triggerconstantcontract?apikey={apikey}

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 or estimating the energy consumption.

Note:

  • TriggerConstantContract operation will not generate an on-chain transaction, nor will it change the status of the current node.
  • For estimating energy: use triggerconstantcontract to call the non-readonly method of the contract, and 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 decodingopen in new window

请求参数说明:

  • 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.
  • visible: boolean. Optional.Whehter the address is in base58 format.

Request

curl --location -g 'https://services.tokenview.io/vipapi/nodeservice/trx/wallet/triggerconstantcontract?apikey={apikey}' \
--data '{
  "owner_address": "410000000000000000000000000000000000000000",
  "contract_address": "41a614f803b6fd780986a42c78ec9c7f77e6ded13c",
  "function_selector": "balanceOf(address)",
  "parameter": "000000000000000000000000a614f803b6fd780986a42c78ec9c7f77e6ded13c",
  "visible": true
}'

Response


deploycontract

POST https://services.tokenview.io/vipapi/nodeservice/trx/wallet/deploycontract?apikey={apikey}

Deploys a contract. Returns TransactionExtention, which contains an unsigned transaction.

请求参数说明:

  • abi: json. Smart Contract's Application Binary Interface
  • bytecode: string. The compiled contract's identifier, used to interact with the Virtual Machine.
  • fee_limit: int32. Maximum TRX consumption, measured in SUN (1 TRX = 1,000,000 SUN).
  • parameter: string. Parameter passed to the constructor of the contract. Call the virtual machine format of the parameter [1, 2], use the js tool provided by remix, convert the parameter array [1, 2] called by the contract caller into the parameter format required by the virtual machine.
  • origin_energy_limit: int32. The max energy which will be consumed by the owner in the process of execution or creation of the contract, is an integer which should be greater than 0.
  • owner_address: string. Contract owner address, converted to a hex string
  • name: string. Contract name
  • call_value: int32. Amount of TRX transferred with this transaction, measured in SUN (1TRX = 1,000,000 SUN)
  • consume_user_resource_percent: int32. The same as User Pay Ratio. The percentage of resources specified for users who use this contract. This field accepts integers between [0, 100]. If it is 0, it means the user does not consume resources until the developer resources are exhausted. However, it is strongly recommended to set the value between 1 and 99 (inclusive). This is prevent the contract developer from potential malicious infinite loop time out attacks.
  • permission_id: int32. Optional. Whehter the address is in base58 format.
  • visible: boolean. Optional. Whehter the address is in base58 format.

Request

curl --location -g 'https://services.tokenview.io/vipapi/nodeservice/trx/wallet/deploycontract?apikey={apikey}' \
--data '{
  "abi": "[{\"constant\":false,\"inputs\":[{\"name\":\"key\",\"type\":\"uint256\"},{\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"key\",\"type\":\"uint256\"}],\"name\":\"get\",\"outputs\":[{\"name\":\"value\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]",
  "bytecode": "608060405234801561001057600080fd5b5060de8061001f6000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631ab06ee58114604d5780639507d39a146067575b600080fd5b348015605857600080fd5b506065600435602435608e565b005b348015607257600080fd5b50607c60043560a0565b60408051918252519081900360200190f35b60009182526020829052604090912055565b600090815260208190526040902054905600a165627a7a72305820fdfe832221d60dd582b4526afa20518b98c2e1cb0054653053a844cf265b25040029",
  "fee_limit": 0,
  "parameter": "string",
  "origin_energy_limit": 0,
  "owner_address": "41D1E7A6BC354106CB410E65FF8B181C600FF14292",
  "name": "SomeContract",
  "call_value": 0,
  "consume_user_resource_percent": 0,
  "permission_id": 0,
  "visible": true
}'

Response


updatesetting

POST https://services.tokenview.io/vipapi/nodeservice/trx/wallet/updatesetting?apikey={apikey}

Update the consume_user_resource_percent parameter of a smart contract.

请求参数说明:

  • owner_address: string. required. Transaction creator address, in hex string format.
  • contract_address: string. required. The address of the contract to be modified, in hex string format.
  • consume_user_resource_percent: int32. required. Consume user's resource percentage. It should be an integer between [0, 100]. if 0, means it does not consume user's resource until the developer's resource has been used up
  • permission_id: int32. Optional, for multi-signature use
  • visible: boolean. Optional.Whehter the address is in base58 format.

Request

curl --location -g 'https://services.tokenview.io/vipapi/nodeservice/trx/wallet/updatesetting?apikey={apikey}' \
--data '{
  "owner_address": "41608F8DA72479EDC7DD921E4C30BB7E7CDDBE722E",
  "contract_address": "41a7837ce56da0cbb28f30bcd5bff01d4fe7e4c6e3",
  "consume_user_resource_percent": 0,
  "permission_id": 0,
  "visible": true
}'

Response


updateenergylimit

POST https://services.tokenview.io/vipapi/nodeservice/trx/wallet/updateenergylimit?apikey={apikey}

Update the origin_energy_limit parameter of a smart contract.

❗️Origin Energy Limit
Starting with Java-Tron Odyssey 3.2 release, this parameter is required for deploying new contracts, and the value should be larger than 0.
For contracts already deployed on the Mainnet prior to Odyssey 3.2, the
value is stored as 0, but treated as maximum = 10,000,000.

请求参数说明:

  • owner_address: string. Transaction creator address, in hex string format.
  • contract_address: string. The address of the contract to be modified, in hex string format.
  • origin_energy_limit: int32. The maximum energy the creator sets. The greatest amount of energy the creator consumes during contract execution or creation process.
  • permission_id: int32. Optional, for multi-signature use
  • visible: boolean. Optional.Whehter the address is in base58 format.

Request

curl --location -g 'https://services.tokenview.io/vipapi/nodeservice/trx/wallet/updateenergylimit?apikey={apikey}' \
--data '{
  "owner_address": "41608F8DA72479EDC7DD921E4C30BB7E7CDDBE722E",
  "contract_address": "41a7837ce56da0cbb28f30bcd5bff01d4fe7e4c6e3",
  "origin_energy_limit": 0,
  "permission_id": 0,
  "visible": true
}'

Response


clearabi

POST https://services.tokenview.io/vipapi/nodeservice/trx/wallet/clearabi?apikey={apikey}

To clear the ABI info of a smart contract.

请求参数说明:

  • owner_address: string. Owner address of the smart contract. If visible=true, use base58check format, otherwise use hex format.
  • contract_address: string. Smart contract address. If visible=true, use base58check format, otherwise use hex format.
  • visible: boolean. Optional. Defaults to false. Whether addresses are in base58check format.

Request

curl --location -g 'https://services.tokenview.io/vipapi/nodeservice/trx/wallet/clearabi?apikey={apikey}' \
--data '{
  "owner_address": "41608F8DA72479EDC7DD921E4C30BB7E7CDDBE722E",
  "contract_address": "41a7837ce56da0cbb28f30bcd5bff01d4fe7e4c6e3",
  "visible": true
}'

Response


estimateenergy

POST https://services.tokenview.io/vipapi/nodeservice/trx/wallet/estimateenergy?apikey={apikey}

Estimate the energy required for the successful execution of smart contract transactions.

Note:

  • This API is closed by default. To open this interface, the two configuration items vm.estimateEnergy and vm.supportConstant must be enabled in the node configuration file at the same time.
  • The wallet/triggerconstantcontract
    API can be used to estimate the energy consumption value of calling
    most smart contracts on the chain, such as USDD, USDT, USDC, TUSD, etc.
    Meanwhile, Compared to the existing wallet/triggerconstantcontract API, wallet/estimateEnergy
    API will be more accurate in estimating the energy consumption of
    calling a small number of special contract. But for FullNode, enabling
    the wallet/estimateEnergy API is optional. So please pay attention that when developers call wallet/estimateEnergy,
    if the error message shows that the node does not support this function
    when calling the new API (this node does not support estimate energy),
    it is recommended to continue using the wallet/triggerconstantcontract API to estimate energy consumption.
  • estimateenergy will not generate an on-chain transaction, nor will it change the status of the current node.
  • The energy_required field in the returned value is the energy estimated amount. Therefore, the fee_limit of the transaction can be set to energy_required x energy unit price.
  • Parameter encoding and decoding example: Parameter and return value encoding and decodingopen in new window

请求参数说明:

  • 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.
  • visible: boolean. Optional.Whehter the address is in base58 format.

Request

curl --location -g 'https://services.tokenview.io/vipapi/nodeservice/trx/wallet/estimateenergy?apikey={apikey}' \
--data '{
  "owner_address": "410000000000000000000000000000000000000000",
  "contract_address": "41a614f803b6fd780986a42c78ec9c7f77e6ded13c",
  "function_selector": "balanceOf(address)",
  "parameter": "000000000000000000000000a614f803b6fd780986a42c78ec9c7f77e6ded13c",
  "visible": true
}'

Response


上次编辑于: