Reemplazo el web3 de mi MetaMask con web3.js 1.0.0-beta.34, y getGasPrice siempre devuelve nulo en cada red.
window.web3 = new Web3(web3.currentProvider);
console.log('web3.version = ' + web3.version);
web3.eth.getGasPrice(gasPrice => {
console.log('gasPrice = ' + gasPrice);
});
es decir, de mainnet a Ropsten a mi registro de red privada (ganache-cli) --
web3.version = 1.0.0-beta.34
gasPrice = null
¿Alguien más tiene la misma experiencia? ¿Qué pudo haber salido mal?
Resulta que la sintaxis correcta para web3 1.0 debería ser --
web3.eth.getGasPrice().then(gasPrice => {
console.log('gasPrice = ' + gasPrice);
});
que registra --
gasPrice = 20000000000
Otra forma asíncrona :
let transaction = await any_function;
let gasUsed = transaction.receipt.gasUsed;
let txInfo = await web3.eth.getTransaction(transaction.tx);
let gasPrice = txInfo.gasPrice;
console.log(gasPrice);
Maulik Vora
jerry ji