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

16 lines
377 B
JavaScript
Raw Normal View History

import { ethers } from "ethers"
2023-01-18 10:26:35 +08:00
const URL = "https://eth-mainnet.public.blastapi.io"
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()
const txs = await Promise.all(
latest.transactions.map(t => p.getTransactionReceipt(t)),
)
2023-01-18 10:26:35 +08:00
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))