Skip to content

Instantly share code, notes, and snippets.

@dapplion
Created March 10, 2023 07:39
Show Gist options
  • Save dapplion/fe87aec29d261acf8dc767937878b404 to your computer and use it in GitHub Desktop.
Save dapplion/fe87aec29d261acf8dc767937878b404 to your computer and use it in GitHub Desktop.
Beacon chain: count withdrawal credentials by type
import requests
# make the API request
url = "http://localhost:4000/eth/v1/beacon/states/head/validators"
response = requests.get(url)
# check if request was successful
if response.status_code != 200:
print(f"Error: API request returned status code {response.status_code}")
exit()
# extract withdrawal credentials from response
data = response.json()["data"]
withdrawal_credentials = [v["validator"]["withdrawal_credentials"] for v in data]
# count withdrawal credentials that start with 0x00 or 0x01
num_00 = sum(1 for c in withdrawal_credentials if c.startswith("0x00"))
num_01 = sum(1 for c in withdrawal_credentials if c.startswith("0x01"))
# print the results
print(f"Number of withdrawal credentials starting with 0x00: {num_00}")
print(f"Number of withdrawal credentials starting with 0x01: {num_01}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment