Norman Fung

Here’s the code, I think it should be rather self explanatory, it uses bisection search to look for the block given a particular cutoff (Timestamp, not Block Number), have a look at the referenced article from http://amsi.org.au/ if you haven’t done it before.

Usage should also be apparent from unit tests:

Please note:

a. search_step_size is “initial” step size. Set this to a bigger number so things converges more quickly. When the search passes the target block for the first time, it’d automatically half the step size to recursively converge more accurately to target block.

b. if precision_sec is too small, your search may not converge.

c. Real life application? https://norman-lm-fung.medium.com/web3-py-fetching-all-transfer-events-on-single-tokens-from-a-given-timestamp-90bd6ec08e33

--

--

Norman Fung

Norman Fung

#python #web3 #crypto #trading #nft #blockchain #smartcontract #journey2makemoneyscientifically