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

const provider = new HDWalletProvider(
   'rinkeby url'

const  web3 = new Web3(provider);

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

console.log('Starting deploy 1');
const deploy = async () => {
  console.log('Starting deploy 2');
    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, arguments: ['Hi there!']})
                    .send({ gas: '1000000', from: accounts[0]}, function (error) {
                                        console.log('Error: ', JSON.stringify(error));

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


I'm having a problem with this script

The script dosent get past the const accounts = await web3.eth.getAccounts(); line

Its like it just returns out of the function

No console log messages are printed after this line

Does anyone know what the problem could be

It also doesn't throw any errors

Console output is Starting deploy 1 Starting deploy 2 end

If tried surrounding it with a try cat

  • Problem was i didn't have http:// in my infura URL. Solved now – Jessica May 2 at 14:59
  • Why doesn't it throw an error with a bad url? Is it because it is async? It just times out i guess. – Jessica May 3 at 9:51

Your Answer

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

Browse other questions tagged or ask your own question.