# Which block has the lowest hash? [duplicate]

This question already has an answer here:

Which block has the lowest hash currently? Is there a website that allows to sort blocks by hash?

## marked as duplicate by MCCCS, Community♦Jun 21 '18 at 13:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

## 2 Answers

I don't think there is a site that will show you this information, but it is fairly trivial to find out.

Here's an old Bitcointalk thread that discusses this: https://bitcointalk.org/index.php?topic=29675.0

Here's a python script that will calculate it for you. You will need a bitcoind for it to connect to:

``````from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import binascii
import struct

def uint256_to_str(u):
rs = b""
for i in range(8):
rs += struct.pack("<I", u & 0xFFFFFFFF)
u >>= 32
return binascii.hexlify(rs)

def uint256_from_str(s):
s = binascii.unhexlify(s)
r = 0
t = struct.unpack("<IIIIIIII", s[:32])
for i in range(8):
r += t[i] << (i * 32)
return r

def byteswap(a):
return "".join(reversed([a[i:i+2] for i in range(0, len(a), 2)]))

# rpc_user and rpc_password are set in the bitcoin.conf file
rpc_user = "user"
rpc_password = "password"
rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:8332"%(rpc_user, rpc_password))

best_hash = uint256_from_str("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
best_height = 0
counter = 0

while True:
try:
commands = [ [ "getblockhash", height] for height in range(counter, counter + 10000) ]
block_hashes = rpc_connection.batch_(commands)

for block_hash in block_hashes:
block_uint256 =  uint256_from_str(byteswap(block_hash))
if block_uint256 < best_hash:
best_hash = block_uint256
best_height = counter
counter += 1

print("Processed " + str(counter) + " blocks")
except Exception as e:
print(e)
break;

print("Lowest Block Hash: " + byteswap(uint256_to_str(best_hash).decode()) + " at block height " + str(best_height))
``````

This script gave me the following output:

``````Lowest Block Hash: 00000000000000000000011246f099d94f91628d71c9d75ad2f9a06e2beb7e92 at block height 458091
``````

I improved on this to print the lowest 50 block hashes as well as their heights and the dates they were generated:

``````from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import datetime

# rpc_user and rpc_password are set in the bitcoin.conf file
rpc_user = "user"
rpc_password = "password"
rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:8332" %
(rpc_user, rpc_password))

block_cnt = rpc_connection.getblockcount()
block_hashes = []

for n in range(0, block_cnt, 1000):
commands = [["getblockhash", h] for h in range(n, min(n+1000, block_cnt))]
block_hashes += rpc_connection.batch_(commands)

block_hashes.sort()

commands = [["getblock", block_hash] for block_hash in block_hashes[0:50]]
blocks = rpc_connection.batch_(commands)

for block in blocks:
time = datetime.datetime.fromtimestamp(block['time']).strftime('%Y-%m-%d')
print(block['hash'], block['height'], time)
``````

A new record was just set yesterday!

``````0000000000000000000000bb5b432a764ad6c7acf677dcd99161abfdf68e698e 500174 2017-12-19
``````