DeployContract

POST: http://172.104.51.182:16667/wallet/deploycontract

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

BODY PARAMS {

abi string

bytecode string

function_selector string

parameter string

fee_limit int32

origin_energy_limit int32

owner_address string

name string

call_value int32

consume_user_resource_percent int32

permission_id int32 (Optional)

visible boolean (Optional)

}

Note:

  • abi : Smart Contract's Application Binary Interface

  • bytecode: The compiled contract's identifier, used to interact with the Virtual Machine.

  • fee_limit is maximum TRX consumption, measured in SUN (1 TRX = 1,000,000 SUN).

  • 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.

  • origin_energy_limit : 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 that triggers the contract, converted to a hex string

  • name is contract name

  • call_value is amount of TRX transferred with this transaction, measured in SUN (1 TRX = 1,000,000 SUN).

  • consume_user_resource_percent : 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, whether the address is in base58 format.

  • visible: whether the address is in base58check format.

Example:

curl --request POST --url http://172.104.51.182:16667/wallet/deploycontract --header 'Accept: application/json' --header 'Content-Type: application/json' --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", "owner_address": "WFzFXoQCgUeoApjejKM9B46NgFGHXvUyKz", "name": "delpoyContracthungtest", "origin_energy_limit":1000000000, "consume_user_resource_percent": 10, "visible":true }

Input:

{

"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", "owner_address": "WFzFXoQCgUeoApjejKM9B46NgFGHXvUyKz", "name": "delpoyContracthungtest", "origin_energy_limit":1000000000, "consume_user_resource_percent": 10, "visible":true

}

Response:

{

"visible": true, "txID": "6fe61a44390f1c3157aea50b99b9281fcf74469a36d95e66cd513388546a85fe", "contract_address": "411e1980e0a7acd3af82c24e6962bed85116d727c5", "raw_data": { "contract": [ { "parameter": { "value": { "owner_address": "WFzFXoQCgUeoApjejKM9B46NgFGHXvUyKz", "new_contract": { "bytecode": "608060405234801561001057600080fd5b5060de8061001f6000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631ab06ee58114604d5780639507d39a146067575b600080fd5b348015605857600080fd5b506065600435602435608e565b005b348015607257600080fd5b50607c60043560a0565b60408051918252519081900360200190f35b60009182526020829052604090912055565b600090815260208190526040902054905600a165627a7a72305820fdfe832221d60dd582b4526afa20518b98c2e1cb0054653053a844cf265b25040029", "consume_user_resource_percent": 10, "name": "delpoyContracthungtest", "origin_address": "WFzFXoQCgUeoApjejKM9B46NgFGHXvUyKz", "abi": { "entrys": [ { "inputs": [ { "name": "key", "type": "uint256" }, { "name": "value", "type": "uint256" } ], "name": "set", "stateMutability": "Nonpayable", "type": "Function" }, { "outputs": [ { "name": "value", "type": "uint256" } ], "constant": true, "inputs": [ { "name": "key", "type": "uint256" } ], "name": "get", "stateMutability": "View", "type": "Function" } ] }, "origin_energy_limit": 1000000000 } }, "type_url": "type.googleapis.com/protocol.CreateSmartContract" }, "type": "CreateSmartContract" } ], "ref_block_bytes": "774b", "ref_block_hash": "267e9e3b5f5f2ed3", "expiration": 1639986108000, "timestamp": 1639986048426 }, "raw_data_hex": "0a02774b2208267e9e3b5f5f2ed340e0aca8b6dd2f5ae903081e12e4030a30747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e437265617465536d617274436f6e747261637412af030a15414203485a535a4072c9fbfaaddfe2a010ad0bcdb01295030a15414203485a535a4072c9fbfaaddfe2a010ad0bcdb01a5c0a2b1a03736574220e12036b65791a0775696e743235362210120576616c75651a0775696e74323536300240030a2d10011a03676574220e12036b65791a0775696e743235362a10120576616c75651a0775696e743235363002400222fd01608060405234801561001057600080fd5b5060de8061001f6000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631ab06ee58114604d5780639507d39a146067575b600080fd5b348015605857600080fd5b506065600435602435608e565b005b348015607257600080fd5b50607c60043560a0565b60408051918252519081900360200190f35b60009182526020829052604090912055565b600090815260208190526040902054905600a165627a7a72305820fdfe832221d60dd582b4526afa20518b98c2e1cb0054653053a844cf265b25040029300a3a1664656c706f79436f6e747261637468756e6774657374408094ebdc0370aadba4b6dd2f"

}

==> Continue you call gettransactionsign API then call broadcasttransaction API

We will the final result: The transaction created success on WEL network.

{

"result": true, "txid": "6fe61a44390f1c3157aea50b99b9281fcf74469a36d95e66cd513388546a85fe"

}

Last updated