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

31 lines
464 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)
2023-02-06 01:53:34 +08:00
await p._networkPromise
2023-01-18 10:26:35 +08:00
const latest = await p.getBlock()
2023-02-06 01:53:34 +08:00
latest
2023-01-18 10:26:35 +08:00
const txs = await Promise.all(latest.transactions.map(t =>
p.getTransactionReceipt(t)
))
2023-02-06 01:53:34 +08:00
2023-01-18 10:26:35 +08:00
const totalGas = txs.reduce((gas,tx) =>
gas.add(tx.gasUsed), ethers.BigNumber.from(0))
2023-02-06 01:53:34 +08:00
totalGas.add(25)