I am creating a contract on my local blockchain network using web3. On my node , contact is created and address is generated. But on node application, response is struck.

Here is my node code:

const Web3 = require('web3')
const web3 = new Web3(new Web3.providers.HttpProvider(""))
//const web3 = new Web3(ganache.provider());
const compiledFactory = require('./ethereum/build/CampaignFactory.json')

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

    addr = await web3.eth.personal.newAccount('123456');

    factory = await new web3.eth.Contract(JSON.parse(compiledFactory.interface))
    .deploy({ data: '0x' + compiledFactory.bytecode })
    .send({ from: accounts[0], gas: '1000000' });



Here is console from node app that is stuck after

[ '0xDa8512CBD5c5eaa1213e5A7bEefAf35e9bA2c9EA',
  '0xD9FcDA95002A09d7be394F085fAEC2a1f3d28476' ]

and here is the logs from node:

INFO [08-09|03:28:10.027] Submitted contract creation              fullhash=0x63ac15fcc23f19aa44cd225dbacf7ea30069d3e106987daf63a4238caab4b73c contract=0x31F82590e051A224e7d8d63eB54f434d6073aB06

Can anybody help? Why I am not getting address on nodejs application?

  • do you have balance on that account which will deploy the contract?!
    – Majd TL
    Aug 9 '19 at 8:15
  • Yes account have balance. Contract is deployed also. But waiting for response in nodejs application. Aug 9 '19 at 8:17

Here is one of my deploy scripts. Feel free to modify it as needed.

Code which deploys a smart contract | deploy.js

const Web3 = require('web3');
const { interface, bytecode } = require('./compile');

const web3 = new Web3(new Web3.providers.HttpProvider(""))

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 })
      .send( { gas: '5000000', from:accounts[0] });

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

Code which compiles smart contract code (creates interface and bytecode) | compile.js

const path = require('path');
const fs = require('fs');
const solc = require('solc');

const contractPath = path.resolve(__dirname, 'contracts', 'Contract.sol');
const source = fs.readFileSync(contractPath, 'utf8');

module.exports = solc.compile(source, 1).contracts[':Contract'];

Contract path needs to contain the path to the smart contract .sol file. In module.exports .contracts[':Contract']; the :Contract needs to be replaced with the name of the contract.

In case you need further information just ask.


if you're using test net from another provider like rinkeby or etc. process for deploy a contract took little longer for getting return value. approximately 6-8 minutes


I'm not sure what the return value factory is, so dumping it on the console may be blank if it's undefined. When you say it is hanging, do you mean your NodeJS application never completes, or just that it prints nothing after the list of addresses?

In any case, as you say, it seems like just a display problem, not a contract deploying problem. You can add another console.log('Done') line after console.log(factory), or even console.log(JSON.stringify(factory)), to make sure the script is actually completing.

Usually truffle or web3 methods like to return a transaction hash from methods that send transactions to the blockchain, such as 0x63ac15fcc23f19aa44cd225dbacf7ea30069d3e106987daf63a4238caab4b73c in your example above, but I've never used the deploy and send methods above.

  • Yes it is hanging. Nodejs application never completes it. I added logs like done below, but the code execution struck on contract creation. Aug 9 '19 at 17:46

I was running into the same problem when deploying locally to a Hardhat development node. Everything seemed to work fine when I didn't wait for the deployment to complete (or if I deployed to a live network).

To fix the issue, I set autoMine: true in my deployment request and things started working just fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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