-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest.py
50 lines (40 loc) · 1.22 KB
/
request.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import requests
from dotenv import load_dotenv
import numpy as np
import matplotlib.pyplot as plt
load_dotenv()
def main():
FIRST_POS_BLOCK = 15537394
url = os.getenv("ETH_MAINNET_URL")
most_recent_block = {
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 83,
}
blocknumber = requests.post(url, json=most_recent_block).json()
length = int(blocknumber["result"], 16) - FIRST_POS_BLOCK
block = FIRST_POS_BLOCK
prevrandao_values = []
for idx in range(length):
payload = {
"jsonrpc": "2.0",
"method": "eth_getBlockByNumber",
"params": [hex(block), True],
"id": 1,
}
response = requests.post(url, json=payload).json()
prevrandao = response["result"]["mixHash"]
prevrandao_values.append(int(prevrandao, 0))
block += 1
np.savetxt("prevrandao_values.csv", prevrandao_values, delimiter=",")
plt.hist(np.array(prevrandao_values, dtype=float) / 10**77, bins=75)
plt.gca().set(
title="RANDAO Histogram",
ylabel="Frequency",
xlabel="Normalised (10**77) RANDAO Values",
)
plt.show()
if __name__ == "__main__":
main()