1

When ti try to estimate gas for my contract to deploy, I always get undefined result.

This is my code:

const toDeploy = contract.deploy({ 
    data: '0x' + bytecode, 
    arguments: [[web3.utils.asciiToHex('Name1'),web3.utils.asciiToHex('Name2')]]
});

const getGasPrice = () => {
    return new Promise((resolve, reject) => {
        web3.eth.getGasPrice((error, result) => {
            if (error) reject(error)

            console.log('Gas price: ', result);
            resolve(web3.utils.toHex)
        })
    })
}

const getGasLimit = (toDeploy) => {
    return new Promise((resolve, reject) => {

        toDeploy.estimateGas((error, result) => {
            if (error) reject(error)

            this.gasLimit = result
            this.minGasLimit = result

            console.log('Gas : ', result); // PROBLEM HERE!
            resolve(web3.utils.toHex(parseInt(result * 1.1)))
        })
    })
}

Promise.all([getGasPrice(), getGasLimit(toDeploy)])
    .then(values => {
        const opt = {
            from: web.eth.accounts[0],
            gas: values[1],
            gasPrice: values[0]
        }
        return opt
    })
    .then(opt => {
        toDeploy
            .send(opt)
            .then((instance) => { 
                console.log("Contract mined at " + instance.options.address);
                contractInstance = instance; 
            });
    })
    .catch(e => 
        console.log(e)
    );

Can anyone help me? Thank you

2
  • Are you using web3 v1.0 or v0.20 or some version of truffle?
    – Ismael
    Commented Mar 1, 2018 at 4:10
  • @Ismael I'm using web3 v1.0
    – imfabio
    Commented Mar 1, 2018 at 20:30

0

Your Answer

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