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