There's more...

You can also deploy the contract using the contract instance. Consider the following example of deploying a contract in both v0.2x.x and v1.x.x to understand more:

var bytecode = output.contracts["HelloWorld"].bytecode;
var abi = output.contracts["HelloWorld"].interface;

// For v0.2x.x
var helloworldContract = web3.eth.contract(abi);
var helloworld = helloworldContract.new({
from: "
0xce5C2D181f6DD99091351f6E6056c333A969AEC9",
data: byteCode,
gas: 4700000
}, function (e, contract){
if (typeof contract.address !== "undefined") {
console.log("address: " + contract.address);
}
});

// For v1.x.x
var helloWorld = new web3.eth.Contract(abi);
helloWorld.deploy({ data: byteCode,
arguments: [] // Constructor arguments
}) .send({ from: "0x1234567890123456789012345678901234567891", gas: 4700000 }) .on("error", function(error){
console.error(error);
}) .on("receipt", function(receipt) { console.log(receipt.contractAddress); });

For larger contracts, you may have to increase the gas amount for execution. This can be estimated with the contract instance:

// For v0.2x.x
var gas = web3.eth.estimateGas({ data: byteCode }); console.log(gas);

// For v1.x.x
helloWorld.deploy({
data: byteCode,
arguments: []
})
.estimateGas(function(err, gas){
console.log(gas);
});
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.93.169