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

16 lines
409 B
JavaScript
Raw Normal View History

2023-02-13 17:39:34 +08:00
import {ethers} from 'https://unpkg.com/ethers@5.7.2/dist/ethers.esm.js'
2023-01-18 10:26:35 +08:00
2023-05-18 23:15:10 +03:00
const URL = 'https://rpc.ankr.com/eth_goerli'
2023-01-18 10:26:35 +08:00
const p = ethers.getDefaultProvider(URL)
2023-02-13 17:39:34 +08:00
2023-01-18 10:26:35 +08:00
const latest = await p.getBlock()
2023-05-13 11:13:29 +03:00
const txs = await Promise.all(latest.transactions.map(t =>
2023-01-18 10:26:35 +08:00
p.getTransactionReceipt(t)
))
2023-05-18 23:15:10 +03:00
const totalGas = txs
.filter(tx => tx != null)
.reduce((gas,tx) => gas.add(tx.gasUsed), ethers.BigNumber.from(0))