Peera.

Bài viết

Chia sẻ kiến thức của bạn.

0x515e...c7d4.Peera.
Dành choAll Things Web3Oct 16, 2022
Hỏi đáp Chuyên Gia

How to get BaseFeePerGas of an old block with ethers.js/hardhat

I am working on a personal project and I was wondering if there's a way to get the BaseFeePerGas of a historical block using ethers.js

  • blockchain
2
1
Chia sẻ
Bình luận
.

Câu trả lời

1
Sergey Ilin.
Oct 16 2022, 17:59

I could not find a way to get directly with providers methods in ethers.js. However, there is RCP endpoint ethfeeHistory that can provide this information. RPC endpoint can be called with method send:

var block = await ethers.provider.send("eth_feeHistory", [1, "latest", []]);

The second argument is block number. It can be "latest", "pending", or block number in hex format.

Notice that this endpoint typically can return block history up to 1024 blocks max (depends on the RPC provider).

Alternatively, you can use something like Ethers scan API to get this information - https://docs.etherscan.io/api-endpoints/geth-parity-proxy#eth_getblockbynumber.

Their free tier maybe enough for a personal project needs. Ethers js has a provider for Etherscan - https://docs.ethers.io/v5/api/providers/api-providers/#EtherscanProvider. However, it is currently not documented well and I personally never used it.

1
Bình luận
.

Bạn có biết câu trả lời không?

Hãy đăng nhập và chia sẻ nó.

Web3 (also known as Web 3.0) is an idea for a new iteration of the World Wide Web which incorporates concepts such as decentralization, blockchain technologies, and token-based economics.

142Bài viết198Câu trả lời
Sui.X.Peera.

Kiếm phần của bạn từ 1000 Sui

Tích lũy điểm danh tiếng và nhận phần thưởng khi giúp cộng đồng Sui phát triển.

Chiến dịch phần thưởngTháng Sáu
Chúng tôi sử dụng cookie để đảm bảo bạn có trải nghiệm tốt nhất trên trang web của chúng tôi.
Thêm thông tin