async/await example

This commit is contained in:
Dmitry Vasilev
2023-01-18 10:26:35 +08:00
parent c4768bc0e6
commit 943d2be434
2 changed files with 14 additions and 24 deletions

View File

@@ -0,0 +1,14 @@
import {ethers} from 'https://unpkg.com/ethers/dist/ethers.esm.js'
const URL = 'https://ethereum-goerli-rpc.allthatnode.com'
const p = ethers.getDefaultProvider(URL)
const latest = await p.getBlock()
const txs = await Promise.all(latest.transactions.map(t =>
p.getTransactionReceipt(t)
))
const totalGas = txs.reduce((gas,tx) =>
gas.add(tx.gasUsed), ethers.BigNumber.from(0))