It's seem that is a very common topic but I couldn't find the solution in other questions, sorry for asking it again. I'm following a beginner example, trying to deploy a contract in Rinkeby Network through Infura node.

This is the contract I want to deploy:

pragma solidity ^0.4.22;

contract Inbox {
    string public message;

    constructor(string initialMessage) public {
        message = initialMessage;

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

This is the Deploy.js

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

const provider = new HDWalletProvider(
    '  //Mnemonic ',
const web3 = new Web3(provider);

const deploy = async () => {
    const accounts = await web3.eth.getAccounts();

    console.log('Deploy from account', accounts[0]);

    const result = await new web3.eth.Contract(JSON.parse(interface))
        .deploy({ data: bytecode, arguments: ['Hi there!'] })
        .send({ gas: '1000000', from: accounts[0] });

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

When I try node deploy.js, the console print the first Console.log of the Deploy function but after waiting it says:

(node:13776) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: The contract code couldn't be stored, please check your gas limit.
(node:13776) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I hope you can help me guys, sorry if it's an easy peasy thing, trying to learn it.

  • does your account have some ethers?
    – Badr Bellaj
    Commented May 3, 2018 at 22:07
  • @BadrBellaj Yes I do, I've put some ethers with faucet.rinkeby.io in my account
    – gbiatturi
    Commented May 3, 2018 at 22:10
  • @Guillermo How did you get the bytecode? Does it have the '0x' at the beginning?
    – Ismael
    Commented May 4, 2018 at 2:40
  • @Ismael No it doesnt. I get my bytecode from my compile.js, I export this through: module.exports = solc.compile(source, 1).contracts[':Inbox'];
    – gbiatturi
    Commented May 4, 2018 at 18:47
  • 1
    The solution offered by @Ismael worked for me. The question is also a duplicate of this question Commented May 7, 2018 at 3:24

1 Answer 1


How did you get the bytecode? Does it have the '0x' at the beginning?

Can you try adding the '0x' when submitting the transaction?

.deploy({ data: '0x' + bytecode, arguments: ['Hi there!'] })

If you put '0x' in front of the bytecode it will assume the rest is in hexadecimal and left it alone.

If there's no '0x' it will convert the whole string to hexadecimal. This is bad because the bytecode will be double the size and completely wrong.

Not the answer you're looking for? Browse other questions tagged or ask your own question.