# Polygon Validator Checkpoint Information

This script fetches information about validators on the Polygon network and their corresponding checkpoints within a specified range. It highlights the latest checkpoints for each validator, displaying information such as checkpoint ID, timestamp, validator name, and total staked amount. To use it, you need to run the script in a Python environment and ensure that necessary libraries, such as `requests`, are installed. Also, make sure you have permission to access the APIs mentioned in the script.

```yaml
import requests
from datetime import datetime

# Desired start and end checkpoint IDs 
start_checkpoint_id = 54360
end_checkpoint_id = 54371


validator_api_url = "https://staking-api.polygon.technology/api/v2/validators?limit=0&offset=1"

last_checkpoints = {}

validator_response = requests.get(validator_api_url)

if validator_response.status_code == 200:
    validator_data = validator_response.json()
    
    proposer_info = {validator["signer"]: {"name": validator["name"], "totalStaked": validator["totalStaked"]} for validator in validator_data["result"]}

    for checkpoint_id in range(start_checkpoint_id, end_checkpoint_id + 1):
        
        api_url = f"https://heimdall-api.polygon.technology/checkpoints/{checkpoint_id}"

        response = requests.get(api_url)

        if response.status_code == 200:
            json_data = response.json()
            proposer = json_data["result"]["proposer"]

            if proposer in last_checkpoints:
                if last_checkpoints[proposer]["timestamp"] < json_data["result"]["timestamp"]:
                    last_checkpoints[proposer] = {
                        "id": json_data["result"]["id"],
                        "timestamp": json_data["result"]["timestamp"],
                        "name": proposer_info.get(proposer, {}).get("name", "Name not found"),
                        "totalStaked": proposer_info.get(proposer, {}).get("totalStaked", "TotalStaked not found"),
                    }
            else:
                last_checkpoints[proposer] = {
                    "id": json_data["result"]["id"],
                    "timestamp": json_data["result"]["timestamp"],
                    "name": proposer_info.get(proposer, {}).get("name", "Name not found"),
                    "totalStaked": proposer_info.get(proposer, {}).get("totalStaked", "TotalStaked not found"),
                }

# Print the final results
for proposer, info in last_checkpoints.items():
    checkpoint_id = info["id"]
    timestamp = info["timestamp"]
    name = info["name"]
    total_staked = int(float(info["totalStaked"]))

    
    datetime_obj = datetime.utcfromtimestamp(timestamp)
    formatted_date = datetime_obj.strftime('%Y-%m-%d %H:%M:%S UTC')

    
    formatted_total_staked = str(total_staked)[:-18]
    formatted_total_staked += " MATIC"

    
    print(f"Proposer: {proposer}")
    print(f"ID: {checkpoint_id}")
    print(f"Timestamp: {formatted_date}")
    print(f"Validator Name: {name}")
    print(f"Total Staked: {formatted_total_staked}")
    print("---")

```

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:

```bash
pip install requests
```

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:

```bash
python3 your_script.py
```

Results:

The script will process the last checkpoint of each validator on a Polygon network (formerly Matic).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stakepool.dev.br/polygon/scripts/polygon-validator-checkpoint-information.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
