This script is useful for checking the validator's activity, notifying you whenever the validator signs a new checkpoint. It provides an efficient way to monitor the validator's actions, ensuring that you are promptly notified upon the signing of a new checkpoint.
import requestsimport timeapi_url = "https://staking-api.polygon.technology/api/v2/monitor/checkpoint-signatures/latest"# Last checkpointNumberlast_checkpoint = Nonemy_validator_id = input("Enter your validator ID:")while True: try: # Make a request to the API response = requests.get(api_url) data = response.json() # Check if the response code is successful if response.status_code == 200 and "result" in data:result = data["result"]new_checkpoint_number = Nonefor item in result:validator_id = item.get("validatorId")checkpoint_number = item.get("checkpointNumber")if checkpoint_number != last_checkpoint and validator_id == my_validator_id:new_checkpoint_number = checkpoint_numberlast_checkpoint = checkpoint_numberprint(f"Validator {my_validator_id} signed a new checkpoint:", new_checkpoint_number)breakif new_checkpoint_number is None:print("No new checkpoints since the last check.")else:print("Request error:", response.status_code)except Exception as e:print("Error:", e)# Wait for some time before making the next requesttime.sleep(60)
Python and Requests Installation:
Make sure you have Python installed on your system. Open the terminal or command prompt. Execute the following command to install the requests library:
pipinstallrequests
Script Execution:
Save the Python script (Your_script.py) in the directory of your choice. Place a file named "addresses.txt" in the same directory as the script, containing the addresses of the validators.
Run the Script:
In the terminal or command prompt, navigate to the directory where the script is located. Execute the script using the following command:
python3your_script.py
Results:
The script will begin monitoring the validator's activity and display messages whenever the validator signs a new checkpoint. You can stop the script at any time by pressing Ctrl + C in the terminal.