I am having trouble deploying a smart contract to the Ropsten testnet. I have dug through a lot of tutorials and questions and I cannot seem to find an suitable answer. Thanks so much for you time!

Currently, the code runs and appears to be successfully deploying. However, it will always use all the gas I provide and never actually deploy. Here is the account I am trying to deploy from: etherscan. You can see that whenever I deploy a contract, it errors out with not enough gas. As I understand it, there should be plenty of gas provided.

Here is my code in question:

const endpoint = 'https://ropsten.infura.io/<mykey>';
const solc = require('solc');
const Web3 = require('web3');
const EthTx = require('ethereumjs-tx');
const web3 = new Web3(new Web3.providers.HttpProvider(endpoint));

const addr1 = "0xa8f157e9c445faad451bd07e6e8780db76f066b3";
const pKey1 = 'd6be926bd949...';               //private key
const pKey1x = new Buffer(pKey1, 'hex');

const source = `contract HellowWorld {         //source in plaintext for readability
  function displayMessage() constant returns (string) {
    return "Hello";
const compiled = solc.compile(source);

const estGasPrice = new Promise((resolve) => {

const getNonce = new Promise((resolve) => {

Promise.all([estGasPrice, getNonce])
  .then(([gasAmt, nonce]) => {
    let tx = new EthTx({
      from:     addr1,
      nonce:    Web3.utils.toHex(nonce),
      value:    Web3.utils.toHex(10000),
      gasLimit: Web3.utils.toHex(10000000),
      gasPrice: Web3.utils.toHex(2000000000),
      data:     Web3.utils.toHex(compiled.contracts[":HellowWorld"].bytecode)
  let serializedTx = `0x${tx.serialize().toString('hex')}`
  web3.eth.sendSignedTransaction(serializedTx, (err, data) => {
    return !err
      ? console.log(`Success! Data: ${data}`)
      : console.log(`Error: ${err}`)
  .catch((err) => {
    console.log('Error' + err)

And for reference, the error I get on the terminal when I run this code is:

Error: Transaction ran out of gas. Please provide more gas:

My intuition is that I haven't formatted the raw transaction correctly. Or it may be that I don't understand how much gas this thing needs. Whatever the case, I appreciate any insight you can provide!

EDIT: My code is refactored, should make more sense

  • Did you try deploying your contract to Ropsten via Remix? I recently also had a problem with deploying my contract to Rinkeby with my own script, but it was deployed correctly with Remix. I know that this is not the answer, but maybe you need solution more than the answer ;) Commented May 9, 2018 at 5:53
  • That's funny you say that, I did deploy via remix and injected web3 and it worked. I'll try some other test nets today and let you know how it goes. Commented May 9, 2018 at 14:31

1 Answer 1


Your problem is you are converting your bytecode to hexadecimal

data:     Web3.utils.toHex(compiled.contracts[":HellowWorld"].bytecode)

And the bytecode appears to already be in hexadecimal. From Etherscan inputData field


You need to only prepend the 0x in front of the bytecode

data:     '0x' + compiled.contracts[":HellowWorld"].bytecode
  • If you are using web3 v1, prepending 0x is no longer required as it is handled by the library if missing. Commented Jun 18, 2018 at 18:05

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.