I am stuck with an issue as the contract works fine with remix ide and local ganache provider but when I am trying to use truffle with infura apis to deploy the contract over rinkeby testnet, I keep getting error.
I have tried with different gas limit values but nothing works and error is consistent.
Error :
(node:9286) UnhandledPromiseRejectionWarning: Error: The contract code couldn't be stored, please check your gas limit.
at Object.callback (/home/vineet/store/project/block-chain/ethereum/inbox/node_modules/web3-core-method/src/index.js:333:46)
at sendTxCallback (/home/vineet/store/project/block-chain/ethereum/inbox/node_modules/web3-core-method/src/index.js:486:29)
at /home/vineet/store/project/block-chain/ethereum/inbox/node_modules/web3-core-requestmanager/src/index.js:147:9
at /home/vineet/store/project/block-chain/ethereum/inbox/node_modules/web3-provider-engine/index.js:152:9
at /home/vineet/store/project/block-chain/ethereum/inbox/node_modules/web3-provider-engine/node_modules/async/internal/once.js:12:16
at replenish (/home/vineet/store/project/block-chain/ethereum/inbox/node_modules/web3-provider-engine/node_modules/async/internal/eachOfLimit.js:61:25)
at /home/vineet/store/project/block-chain/ethereum/inbox/node_modules/web3-provider-engine/node_modules/async/internal/eachOfLimit.js:71:9
at eachLimit (/home/vineet/store/project/block-chain/ethereum/inbox/node_modules/web3-provider-engine/node_modules/async/eachLimit.js:43:36)
at /home/vineet/store/project/block-chain/ethereum/inbox/node_modules/web3-provider-engine/node_modules/async/internal/doLimit.js:9:16
at end (/home/vineet/store/project/block-chain/ethereum/inbox/node_modules/web3-provider-engine/index.js:127:5)
at /home/vineet/store/project/block-chain/ethereum/inbox/node_modules/web3-provider-engine/subproviders/provider.js:20:5
at XMLHttpRequest.request.onreadystatechange (/home/vineet/store/project/block-chain/ethereum/inbox/node_modules/truffle-hdwallet-provider/node_modules/web3/lib/web3/httpprovider.js:118:13)
at XMLHttpRequestEventTarget.dispatchEvent (/home/vineet/store/project/block-chain/ethereum/inbox/node_modules/xhr2/lib/xhr2.js:64:18)
at XMLHttpRequest._setReadyState (/home/vineet/store/project/block-chain/ethereum/inbox/node_modules/xhr2/lib/xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (/home/vineet/store/project/block-chain/ethereum/inbox/node_modules/xhr2/lib/xhr2.js:509:12)
at IncomingMessage.<anonymous> (/home/vineet/store/project/block-chain/ethereum/inbox/node_modules/xhr2/lib/xhr2.js:469:24)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
truffle.js file
module.exports = { networks: { ropsten: { host: "127.0.0.1", port: 8545, network_id: '*', gas: 4700000, gasPrice: 20000000000, }, }, };
deploy.js file contents:
const HDWalletProvider = require('truffle-hdwallet-provider'); const Web3 = require('web3'); const { interface,bytecode } = require('./compile');
const provider = new HDWalletProvider( 'account mnemonic',
'infura api link' );const web3 = new Web3(provider);
const deploy = async () =>{ const accounts = await web3.eth.getAccounts();
console.log('Attempting to deploy from account',accounts[0]);
const result = await new web3.eth.Contract(JSON.parse(interface))
.deploy({ data : bytecode,arguments: ['hello!'] }) .send ({gas: '2000000', from: accounts[0] });console.log('Contract deployed to ',result.options.address); };
deploy();
.deploy({ data: '0x' + bytecode, .. })
. Another possibility is you are setting the gas limit at 2M when you send the contract, it might be low if your contract is complex, try increasing it.