部署智能合约到TRON网络
用法
tronWeb.contract().new({
abi,
bytecode,
feeLimit,
callValue,
userFeePercentage,
originEnergyLimit,
parameters:[param1,2,3,...]
});
参数
Object - 部署的相关信息,该对象包括如下参数:
参数 | 描述 | 数据类型 |
---|---|---|
abi | 智能合约的二进制接口 | String |
bytecode | 智能合约字节码,是可以被虚拟机执行的代码。hexString格式。 | String |
feeLimit | (可选) 部署此合约允许消耗的最大能量费用,单位为sun。 (目前能量单价为420sun) | Integer |
callValue | (可选) 本次调用往合约转入的TRX数量,单位为sun。 | Integer |
userFeePercentage | (可选) 用户能量支付比率,是用户为智能合约执行支付的能量与开发者支付的能量的占比。范围是0-100之间的整数。 | Integer |
originEnergyLimit | (可选) 在一次合约调用过程中,允许消耗合约开发者的最大能量费用。范围是大于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