Statt: web3.eth.getBlock(„latest“).then(console.log)
let getLatestBlock = async () => { return new Promise(function (resolve, reject) { web3.eth.getBlock('latest', function (error, result) { if (error) { reject(error) } else { resolve(result) } }) }) } //usage inside async function let latestBlock = await getLatestBlock() console.log(latestBlock)
Prominenteres Beispiel:
function timeout(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
Schreibe einen Kommentar