This commit is contained in:
Dmitry Vasilev
2023-05-18 23:15:10 +03:00
parent db3166154d
commit 932baf3eed
6 changed files with 35 additions and 65 deletions

View File

@@ -1,41 +1,15 @@
//import {ethers} from 'https://unpkg.com/ethers/dist/ethers.js'
import {ethers} from 'https://unpkg.com/ethers@5.7.2/dist/ethers.esm.js'
const URL = 'https://ethereum-goerli-rpc.allthatnode.com'
const URL = 'https://rpc.ankr.com/eth_goerli'
const p = ethers.getDefaultProvider(URL)
await p._networkPromise
const latest = await p.getBlock()
latest
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))
totalGas.add(21)
/*
const totalGas = txs.reduce((gas,tx) =>
gas + tx.gasUsed, BigInt(0))
totalGas + 1
*/
const totalGas = txs
.filter(tx => tx != null)
.reduce((gas,tx) => gas.add(tx.gasUsed), ethers.BigNumber.from(0))