tronweb.contract.new

Deploy a smart contract.

Usage

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);
}

Important Note: for the userFeePercentage parameter, it is strongly recommended to set the integer value between 1 and 99 (inclusive). Setting as 0 could potentially open the contract developer up to an infinite loop time-out attack.

Parameters

ParameterDescriptionData TypeOption
abiSmart Contract's Application Binary Interface.StringRequired
bytecodeThe compiled contract's identifier, used to interact with the Virtual Machine.StringRequired
feeLimitThe maximum SUN consumes by deploying this contract.
(1TRX = 1,000,000SUN)
Integer, longOptional
callValueAmount of SUN transferred to the contract with this transaction.
(1TRX = 1,000,000 SUN)
IntegerOptional
userFeePercentageThe energy consumption percentage specified for the user calling this contract.Integer between 0 and 100Optional
originEnergyLimitThe 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.IntegerOptional
parametersParameter passed to the constructor of the contract.ArrayOptional, required if constructor needs parameters

Returns
Object

Example

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