For estimate transaction cost, I use web3.eth.getGasPrice()
function. The return callback value always 1Gwei(1,000,000,000) in ROPSTEN.
web3.eth.getGasPrice(function(error, result){
console.log(result);
});
1000000000
Does getGasPrice()
work correctly in Ropsten & Mainnet?
Best Answer
web3.eth.getGasPrice()
is to check the current gas price in the network and will only change if the network gas price changes. If you want to get the amount of gas the transaction will consume then you have to use this functionweb3.eth.estimateGas(callObject [, callback])
provide the address of the contract if using one and the function data which you can obtain by