UnhandledPromiseRejectionWarning Error The contract code couldn t be stored please check your gas limit

0 votes

I am trying to deploy my simple solidity smart contract onto the Rinkeby Network but I keep getting the error:

UnhandledPromiseRejectionWarning: Error: The contract code couldn't be stored, please check your gas limit.

My solidity code is simple

pragma solidity ^0.4.18; 

contract Greetings{ 
  string public message; 

  function Greetings(string initialMessage) public{ 
    message = initialMessage;
  }  

  function setMessage(string newMessage) public {
    message = newMessage;
  }  
}

and my deploy script is:

const HDWalletProvider = require('truffle-hdwallet-provider'); 
const Web3 = require('web3');
const { interface,bytecode} = require('./compile');

const provider = new HDWalletProvider(  
  'twelve word mnemonic...', 
  'https://rinkeby.infura.io/GLm6McXWuaih4gqq8nTY'    
);

const web3 = new Web3(provider);

const deploy = async () => {
    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 World']})      
      .send({from: accounts[0], gas:'1000000'});                              

    console.log('Contract deployed to', result.options.address); 
};

deploy();
Sep 24, 2018 in Blockchain by digger
• 26,740 points
1,681 views

3 answers to this question.

0 votes

Had exactly same problem! Seems it is caused by the bug in the "truffle-hdwallet-provider" version 0.0.5. 

If you do the following should be okay, it worked for me.

npm uninstall truffle-hdwallet-provider
npm install --save truffle-hdwallet-provider@0.0.3

Then I ran the same contract which has deployed successfully.

answered Sep 24, 2018 by slayer
• 29,370 points
0 votes

This issue can be solved by adding the '0x' as the prefix of the bytecode:

.deploy({ data: '0x' + bytecode, arguments: ['Hi there!'] })
answered Sep 24, 2018 by Prakash
0 votes

I believe bytecode is being treated as a single number rather than a series of bytes. Instead of submitting data:bytecode, try:

data:'0x0' + bytecode

it will "preserve" bytecode value as a string

answered Sep 24, 2018 by Teja

Related Questions In Blockchain

0 votes
1 answer

What if Gas required in my program exceeds the limit of 3000000?

Going through your code, I noticed that  you ...READ MORE

answered May 29, 2018 in Blockchain by Perry
• 17,100 points
820 views
0 votes
1 answer

Transfer the gas value of contract to my own address

Works fine for me: pragma solidity ^0.4.0; contract Test ...READ MORE

answered Oct 10, 2018 in Blockchain by Omkar
• 69,220 points
590 views
0 votes
1 answer
0 votes
1 answer

"Migrations" exceeded the block limit (with a gas value you set).

In the error you have posted, in ...READ MORE

answered Jan 17, 2019 in Blockchain by Omkar
• 69,220 points
6,059 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,946 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,469 views
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 69,220 points
1,487 views
0 votes
1 answer

AWS multichain network, "Couldn't connect to the seed node" error

The error says "please check multichaind is ...READ MORE

answered Jul 9, 2018 in Blockchain by slayer
• 29,370 points
1,509 views
0 votes
1 answer

Where is the data stored in blockchain?

The smart contract is just the business ...READ MORE

answered Jun 29, 2018 in Blockchain by slayer
• 29,370 points
1,478 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP