I am trying to deploy a contract on testrpc using web3.js,
contract deploys fine when I deploy it from remix, it uses roughly the same amount of gas as the estimate.
However, when I try to deploy the same contract using web3.js, I keep running into "out of gas" error, even though I am supplying 5x the gas estimate.
I am obviously making some mistake in my deployment script...but I have gone over the script and can't spot the problem....some help from a knowing hand would be much appreciated
let source = fs.readFileSync('./xyz.sol', 'utf8');
let compiledContract = solc.compile(source, 1);
let abi = compiledContract.contracts[':Xyz'].interface;
let bytecode = compiledContract.contracts[':Xyz'].bytecode;
let bContract = new web3.eth.contract(JSON.parse(abi));
let gasEstimate = web3.eth.estimateGas({data : bytecode});
console.log(`GASESTIMATE : ${gasEstimate}`); // <------------ returns value 120000
let deployData = bContract.new.getData(name, choices, closesOn, min, { data : bytecode, });
let rawTx = {
from: runENV.acctAddr,
nonce: web3.toHex(web3.eth.getTransactionCount(runENV.acctAddr)),
gasPrice: web3.toHex(web3.eth.gasPrice),
gasLimit: web3.toHex(5*gasEstimate), // <------------- giving 5x gasestimate
data: deployData,
}
let tx = new Tx(rawTx);
tx.sign(runENV.privateKeyBuffer);
let serialzedTx = tx.serialize().toString('hex');
web3.eth.sendRawTransaction( '0x' + serialzedTx, (err, res) => {
if(err) { console.log(`Error - ${err}`); }
else { console.log(`Xyz contract deployed successfully ${res}`); }
}
);