I am trying to deploy contract using web3js in nodejs on ganache cli test server, but it fails with error as follows :
D:\Thrive\PoC\NodeWebAPI\node_modules\web3\lib\web3\contract.js:149
throw new Error('The contract code couldn\'t be stored, please check your gas amount.');
Error: The contract code couldn't be stored, please check your gas amount.
at Object.callback (D:\Thrive\PoC\NodeWebAPI\node_modules\web3\lib\web3\contract.js:149:43)
at D:\Thrive\PoC\NodeWebAPI\node_modules\web3\lib\web3\method.js:142:25
at D:\Thrive\PoC\NodeWebAPI\node_modules\web3\lib\web3\requestmanager.js:89:9
at XMLHttpRequest.request.onreadystatechange (D:\Thrive\PoC\NodeWebAPI\node_modules\web3\lib\web3\httpprovider.js:118:13)
The code snippet is as follows :
var web3 = connection.getWeb3Object(config.BlockChainServer());
var contractAbi = contractDetails.getContractAbi(contractName);
var contractByteCode = contractAbi.bin;
var gasEstimate = web3.eth.estimateGas({data: contractByteCode});
console.log(gasEstimate);
var contractObject = web3.eth.contract(contractAbi);
var contract = contractObject.new({from: account, gas:1000000,data: "0x" + contractByteCode});
var receipt = web3.eth.getTransactionReceipt(contract.transactionHash);
if (receipt && receipt.contractAddress) {
console.log("Your contract has been deployed at " + config.BlockChainServer + " | Contract address -" + receipt.contractAddress);
}
I have tried sending varying amounts of gas, but I am encountering the same issue. What could be the problem ?