Files
leporello-js/docs/examples/ethers/index.js

15 lines
387 B
JavaScript
Raw Normal View History

2023-01-18 10:26:35 +08:00
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))