Я заменяю web3 моего MetaMask на web3.js 1.0.0-beta.34, и getGasPrice всегда возвращает null в каждой сети --
window.web3 = new Web3(web3.currentProvider);
console.log('web3.version = ' + web3.version);
web3.eth.getGasPrice(gasPrice => {
console.log('gasPrice = ' + gasPrice);
});
то есть из основной сети в Ropsten в журнал моей частной сети ( ganache-cli ) --
web3.version = 1.0.0-beta.34
gasPrice = null
Есть ли у кого-нибудь еще такой же опыт? Что могло пойти не так?
Оказывается, правильный синтаксис для web3 1.0 должен быть --
web3.eth.getGasPrice().then(gasPrice => {
console.log('gasPrice = ' + gasPrice);
});
какие журналы --
gasPrice = 20000000000
Другой асинхронный способ:
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);
Маулик Вора
Джерри Джи