mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
fix ethereum example
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import {ethers} from 'https://unpkg.com/ethers@5.7.2/dist/ethers.esm.js'
|
import {ethers} from 'https://unpkg.com/ethers/dist/ethers.js'
|
||||||
|
|
||||||
const URL = 'https://rpc.ankr.com/eth'
|
const URL = 'https://rpc.ankr.com/eth'
|
||||||
|
|
||||||
@@ -6,6 +6,9 @@ const provider = await ethers.getDefaultProvider(URL)
|
|||||||
|
|
||||||
const latest = await provider.getBlock('latest')
|
const latest = await provider.getBlock('latest')
|
||||||
|
|
||||||
|
/*
|
||||||
|
Find ethereum block by timestamp using binary search
|
||||||
|
*/
|
||||||
async function getBlockNumberByTimestamp(timestamp, low = 0, high = latest.number) {
|
async function getBlockNumberByTimestamp(timestamp, low = 0, high = latest.number) {
|
||||||
if(low + 1 == high) {
|
if(low + 1 == high) {
|
||||||
return low
|
return low
|
||||||
|
|||||||
Reference in New Issue
Block a user