Skip to main content

eth-blocky

Build Status PyPI version License: MIT

Package providing date utilities for finding blocks.

With eth-blocky, you can:

  1. Find the closest block to a given timestamp that happened before
  2. Find the closest block to a given timestamp that happened at the exact same time or after

Installation

  1. pip install eth-blocky

Usage

Provide a timestamp for which you want to find the closest block, and as a result you will get the block object. For more information check out web3 docs

from eth_blocky import EthBlocky

client = EthBlocky(NODE_URL)

# 2021-03-11T12:00:00
timestamp = 1615464000

block = client.closest_block(timestamp, before=True)
print(block.number)
# 12017166

block = client.closest_block(timestamp)
print(block.number)
# 12017167

Method

eth-blocky works as an optimized binary search. Start with finding the first and latest block as the boundry. Left and right block.

Steps:

  1. Get left and right block and their timestamps
  2. Calculate the average time for blocks to being mined in this time range
  3. Estimate distance from start block based on timestamps [1, 3, 10] -> 0.3
  4. Estimate wanted block based on distance
  5. Calculate potential error
  6. Repeat from step 1 with [estimated block - error, estimated block + error] as the left and right block

The process is repeated until left block is equal to right block.

Release files for eth-blocky 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eth-blocky 0.2.3
File Size Uploaded
eth_blocky-0.2.3.tar.gz 3.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for eth-blocky 0.2.3
File Interpreter ABI Platform
eth_blocky-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 6.7 kB

Release files / eth_blocky-0.2.3.tar.gz

Download URL eth_blocky-0.2.3.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7de17fc247a0feed83d9f8d5e89b2ca2263653ecec69b164fa42cd5e2ea74980
BLAKE2b-256 checksum
How to use checksums
44aefcdc18141d764f552e6a49d50e3283b7e8090bbec7584d8f366e50c3a3a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.4 Darwin/21.6.0

Release files / eth_blocky-0.2.3-py3-none-any.whl

Download URL eth_blocky-0.2.3-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a6841ceab83101ab5449e3f3fcfca0ddcd9c1a549e3c4c16d5b719cf759719c3
BLAKE2b-256 checksum
How to use checksums
f0d94302ee7e913654b44ff24f8040c9bdc3b9d370cda08beb5580ea7a23bb9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.4 Darwin/21.6.0

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page