部署智能合约。
用法
let abi = 'some abi for contract';
let code = 'bytecode';
async function deploy_contract(){
let contract_instance = await tronWeb.contract().new({
abi:JSON.parse(abi),
bytecode:code,
feeLimit:1000000000,
callValue:0,
userFeePercentage:1,
originEnergyLimit:10000000,
parameters:[para1,2,3,...]
});
console.log(contract_instance.address);
}
重要说明:对于 userFeePercentage
参数,强烈建议 将整数值设置为1到 99(含)。设置为0 可能会使合同开发人员无法进行无限循环超时攻击。
参数类型
参数 | 描述 | 数据类型 | 选项 |
---|---|---|---|
abi | 智能合约的二进制接口。 | String | 必填 |
bytecode | 已编译的合约的标识符,用于与虚拟机交互,需要是hexString格式。 | String | 必填 |
feeLimit | 部署此合约消耗最大数量的SUN。 | Integer, long | 可选的 |
callValue | 本次调用往合约转账的SUN。 | Integer | 可选的 |
userFeePercentage | 成本用户应支付的比例 | Integer between 0 and 100 | 可选的 |
originEnergyLimit | 创建者设置的,在一次合约执行或创建过程中创建者自己消耗的最大的energy,是大于0的整数。 | Integer | 可选的 |
parameters | 构造函数参数。 | Array | 可选的,如果构造函数需要参数则需要 |
返回值类型
Object
示例
let abi = 'some abi for contract';
let code = 'bytecode';
async function deploy_contract(){
let contract_instance = await tronWeb.contract().new({
abi:JSON.parse(abi),
bytecode:code,
feeLimit:1_00_000_000,
callValue:0,
userFeePercentage:1,
originEnergyLimit:10_000_000
//parameters:[para1,2,3,...]
});
console.log(contract_instance.address);
}
deploy_contract();// Execute the function
Promise { <pending> }
> 414d137bb7f91e8704d712d3967f6a745b9eedd839