I try to create a smart contract (Simple TokenERC20) with sendRawTransaction().

    var firstMainadress = '0x3c7B83E0Fa6f19B1B61e80A73630cB5Db48b700C';
    var secondAdress = '0x38ebbB608fbb40fca07e0EcBAc89e20520BD33f1';
    var privateKey = new Buffer('xxxprivateKeyThatIcantShowHere...','hex')
    var data =  this.byteCode;
    var nonce = this.web3.toHex(this.web3.eth.getTransactionCount(firstMainadress));
    var gasPrice = this.web3.toHex(1000000000);
    var gasLimitHex = this.web3.toHex(1253608);
    var rawTx = { 'data': data, 'nonce': nonce, 'gasPrice': gasPrice, 'gasLimit': gasLimitHex, 'from': firstMainadress};
    var tx = new Tx(rawTx);
    var serializedTx = '0x'+tx.serialize().toString('hex')
    this.web3.eth.sendRawTransaction(serializedTx, function(err, txHash){
      console.log(err, txHash);
      this.deployedContract = txHash;


the txHash is not null, and when i put it on etherscan, i see the bellow error :

the transaction who create the contract exist but he fail in the end !

Can someone help me to found why i have this error message : Warning! Error encountered during contract execution [Out of gas]

Thnaks a lot for your help :)

  • Do you have a link to the etherscan transaction? If your contract has a bug it can cause to consume all the remaining gas.
    – Ismael
    Mar 7, 2018 at 16:50
  • From the link to your transaction in ropsten ropsten.etherscan.io/tx/… it seems you missed to append a '0x' in front of your bytecode. If you look at the input data it is 0x36303630.. and most contracts created with solidity is 0x6060...
    – Ismael
    Jun 1, 2018 at 12:57

1 Answer 1


I don't have enough rep to comment... :/ But, I had a very similar issue and @Ismael 's above answer was spot on! I forgot to prepend my byte code with 0x, and have since added this small validation:

if (tokenSource.byteCode.slice(0,2) !== '0x') {
throw new ValidatorException('Issue with contract source file formatting, ensure starts with \'0x\'', {

Many thanks again to Ismael above

it seems you missed to append a '0x' in front of your bytecode.

  • If Ismael helped you, rate up his comment!
    – Rick Park
    Oct 17, 2018 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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