2

I am trying to deploy my contract to Rinkeby network via Infura. But it actually does not get deploy to network when i run node deploy.js terminal does not spit out the address at which it is deployed. On screen i see it stuck. Please have a look at below screenshot. almost i kept it for a hour, but still same state.

waiting

Upon disconnecting the internet i get the below error, from this i can assume something was going on. there is no feedback system which shows the progress.

err

is there any way to know what is going wrong?

below is my deploy.js code

const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const compiledFactory = require('./build/CampaignFactory.json');

const provider = new HDWalletProvider(
    secret_key,
    'https://rinkeby.infura.io/v3/<infura_key>'

);

const web3 = new Web3(provider);

const deploy = async () => {
    const accounts = await web3.eth.getAccounts();
    console.log('Deploying from account', accounts[0]);
    //console.log('Bytecode is 0x'+compiledFactory.bytecode);
    const result = await new web3.eth.Contract(JSON.parse(compiledFactory.interface))
        //.deploy({ data : '0x' + bytecode})
        .deploy({ data : '0x' + compiledFactory.bytecode})
        .send({gas : '1000000', from : accounts[0]}); 
   // console.log(interface);
   console.log('Contract deployed to ', result.options.address);
};

deploy();

1 Answer 1

0

The problem might be that new is somewhat ambiguous preceding the creation and deployment of a contract instance. You could try adding parenthesis:

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

Or even more explicitly:

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

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.