Skip to content

Latest commit

 

History

History
249 lines (194 loc) · 10.4 KB

File metadata and controls

249 lines (194 loc) · 10.4 KB

Smart contracts

Deploy, trigger, and inspect smart contracts.

DeployContract

> DeployContract [ownerAddress] contractName ABI byteCode constructor params isHex fee_limit consume_user_resource_percent origin_energy_limit value token_value token_id(e.g: TRXTOKEN, use # if don't provided) <library:address,library:address,...> <lib_compiler_version(e.g:v5)> library:address,...>
  • OwnerAddress — the address of the account that initiated the transaction, optional, default is the address of the login account.
  • contractName — name of the smart contract.
  • ABI — compile-generated ABI code.
  • byteCode — compile-generated byte code.
  • constructor, params, isHex — define the format of the bytecode, which determines the way to parse byteCode from parameters.
  • fee_limit — the most TRX the transaction is allowed to consume.
  • consume_user_resource_percent — percentage of user resource consumed, in the range [0, 100].
  • origin_energy_limit — the most developer Energy consumed by triggering the contract once.
  • value — the amount of TRX transferred to the contract account.
  • token_value — number of TRC10.
  • token_id — TRC10 id.

Example:

> deployContract normalcontract544 [{"constant":false,"inputs":[{"name":"i","type":"uint256"}],"name": "findArgsByIndexTest","outputs":[{"name":"z","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]
608060405234801561001057600080fd5b50610134806100206000396000f3006080604052600436106100405763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663329000b58114610045575b600080fd5b34801561005157600080fd5b5061005d60043561006f565b60408051918252519081900360200190f35b604080516003808252608082019092526000916060919060208201838038833901905050905060018160008151811015156100a657fe5b602090810290910101528051600290829060019081106100c257fe5b602090810290910101528051600390829060029081106100de57fe5b6020908102909101015280518190849081106100f657fe5b906020019060200201519150509190505600a165627a7a72305820b24fc247fdaf3644b3c4c94fcee380aa610ed83415061ff9e65d7fa94a5a50a00029 # # false 1000000000 75 50000 0 0 #

Get the result of the contract execution with the getTransactionInfoById command:

> getTransactionInfoById 4978dc64ff746ca208e51780cce93237ee444f598b24d5e9ce0da885fb3a3eb9
{
    "id": "8c1f57a5e53b15bb0a0a0a0d4740eda9c31fbdb6a63bc429ec2113a92e8ff361",
    "fee": 6170500,
    "blockNumber": 1867,
    "blockTimeStamp": 1567499757000,
    "contractResult": [
        "6080604052600436106100405763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663329000b58114610045575b600080fd5b34801561005157600080fd5b5061005d60043561006f565b60408051918252519081900360200190f35b604080516003808252608082019092526000916060919060208201838038833901905050905060018160008151811015156100a657fe5b602090810290910101528051600290829060019081106100c257fe5b602090810290910101528051600390829060029081106100de57fe5b6020908102909101015280518190849081106100f657fe5b906020019060200201519150509190505600a165627a7a72305820b24fc247fdaf3644b3c4c94fcee380aa610ed83415061ff9e65d7fa94a5a50a00029"
    ],
    "contract_address": "TJMKWmC6mwF1QVax8Sy2AcgT6MqaXmHEds",
    "receipt": {
        "energy_fee": 6170500,
        "energy_usage_total": 61705,
        "net_usage": 704,
        "result": "SUCCESS"
    }
}

DeployConstantContract

Run a contract deployment as a constant (read-only) call — the deployment is executed locally against the node and is not broadcast to the chain, so it can be used to check the result and energy cost of a deployment beforehand.

> DeployConstantContract ownerAddress(use # if you own) byteCode constructor params isHex [value token_value token_id]

Takes 5 parameters, or 8 when the trailing value token_value token_id group is supplied.

  • ownerAddress — the address of the account that initiated the transaction; use # if it is your own login account.
  • byteCode — compile-generated byte code.
  • constructor, params, isHex — the constructor signature and its argument values; isHex selects how they are parsed. If either constructor or params is #, no arguments are appended to the byte code.
  • value — the amount of TRX transferred to the contract account.
  • token_value — number of TRC10.
  • token_id — TRC10 id; use # if not provided.

TriggerContract

> TriggerContract [ownerAddress] contractAddress method args isHex fee_limit value token_value token_id
  • OwnerAddress — the address of the account that initiated the transaction, optional, default is the address of the login account.
  • contractAddress — smart contract address.
  • method — the name of the function and parameters; refer to the example.
  • args — parameter value; if you want to call receive, pass # instead.
  • isHex — the format of the parameters method and args; hex string or not.
  • fee_limit — the most TRX allowed for consumption.
  • token_value — number of TRC10.
  • token_id — TRC10 id; if not, use # instead.

Example:

> triggerContract TGdtALTPZ1FWQcc5MW7aK3o1ASaookkJxG findArgsByIndexTest(uint256) 0 false
1000000000 0 0 #
# Get the result of the contract execution with the getTransactionInfoById command
> getTransactionInfoById 7d9c4e765ea53cf6749d8a89ac07d577141b93f83adc4015f0b266d8f5c2dec4
{
    "id": "de289f255aa2cdda95fbd430caf8fde3f9c989c544c4917cf1285a088115d0e8",
    "fee": 8500,
    "blockNumber": 2076,
    "blockTimeStamp": 1567500396000,
    "contractResult": [
        ""
    ],
    "contract_address": "TJMKWmC6mwF1QVax8Sy2AcgT6MqaXmHEds",
    "receipt": {
        "energy_fee": 8500,
        "energy_usage_total": 85,
        "net_usage": 314,
        "result": "REVERT"
    },
    "result": "FAILED",
    "resMessage": "REVERT opcode executed"
}

TriggerConstantContract

> TriggerConstantContract [ownerAddress] contractAddress method args isHex fee_limit value token_value token_id
  • OwnerAddress — the address of the account that initiated the transaction, optional, default is the address of the login account.
  • contractAddress — smart contract address.
  • method — the name of the function and parameters; refer to the example.
  • args — parameter value; if you want to call receive, pass # instead.
  • isHex — the format of the parameters method and args; hex string or not.
  • fee_limit — the most TRX allowed for consumption.
  • token_value — number of TRC10.
  • token_id — TRC10 id; if not, use # instead.

Example:

> TriggerConstantContract TSNEe5Tf4rnc9zPMNXfaTF5fZfHDDH8oyW TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs "balanceOf(address)" 000000000000000000000000a614f803b6fd780986a42c78ec9c7f77e6ded13c true

ClearContractABI

> ClearContractABI [ownerAddress] contractAddress
  • OwnerAddress — the address of the account that initiated the transaction, optional, default is the address of the login account.
  • contractAddress — contract address.

Example:

> ClearContractABI TSNEe5Tf4rnc9zPMNXfaTF5fZfHDDH8oyW TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs

GetContract

Get the details of a smart contract.

> GetContract contractAddress

contractAddress — smart contract address.

Example:

> GetContract TGdtALTPZ1FWQcc5MW7aK3o1ASaookkJxG
{
    "origin_address": "TRGhNNfnmgLegT4zHNjEqDSADjgmnHvubJ",
    "contract_address": "TJMKWmC6mwF1QVax8Sy2AcgT6MqaXmHEds",
    "abi": {
        "entrys": [
            {
                "name": "findArgsByIndexTest",
                "inputs": [
                    {
                        "name": "i",
                        "type": "uint256"
                    }
                ],
                "outputs": [
                    {
                        "name": "z",
                        "type": "uint256"
                    }
                ],
                "type": "Function",
                "stateMutability": "Nonpayable"
            }
        ]
    },
    "bytecode": "608060405234801561001057600080fd5b50610134806100206000396000f3006080604052600436106100405763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663329000b58114610045575b600080fd5b34801561005157600080fd5b5061005d60043561006f565b60408051918252519081900360200190f35b604080516003808252608082019092526000916060919060208201838038833901905050905060018160008151811015156100a657fe5b602090810290910101528051600290829060019081106100c257fe5b602090810290910101528051600390829060029081106100de57fe5b6020908102909101015280518190849081106100f657fe5b906020019060200201519150509190505600a165627a7a72305820b24fc247fdaf3644b3c4c94fcee380aa610ed83415061ff9e65d7fa94a5a50a00029",
    "consume_user_resource_percent": 75,
    "name": "normalcontract544",
    "origin_energy_limit": 50000,
    "code_hash": "23423cece3b4866263c15357b358e5ac261c218693b862bcdb90fa792d5714e6"
}

GetContractInfo

Get the info of a smart contract.

> GetContractInfo contractAddress

contractAddress — smart contract address.

Example:

> GetContractInfo TGdtALTPZ1FWQcc5MW7aK3o1ASaookkJxG

UpdateEnergyLimit / UpdateSetting

Update smart contract parameters.

> UpdateEnergyLimit [ownerAddress] contract_address energy_limit  # Update parameter energy_limit
> UpdateSetting [ownerAddress] contract_address consume_user_resource_percent  # Update parameter consume_user_resource_percent

Create2

Predict the contract address generated after deploying a contract. address is the contract address for executing the create2 instruction, code is the bytecode of the contract to be deployed, and salt is a random salt value.

> Create2 address code salt

Example:

> Create2 TEDapYSVvAZ3aYH7w8N9tMEEFKaNKUD5Bp 5f805460ff1916600190811790915560649055606319600255 2132

EstimateEnergy

Estimate the energy required for the successful execution of a smart contract transaction (confirmed state).

> EstimateEnergy owner_address(use # if you own) contract_address method args isHex [value token_value token_id(e.g: TRXTOKEN, use # if don't provided)]

Example:

> EstimateEnergy TSNEe5Tf4rnc9zPMNXfaTF5fZfHDDH8oyW TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs "balanceOf(address)" 000000000000000000000000a614f803b6fd780986a42c78ec9c7f77e6ded13c true

See also