nearprotocol

How to get all validators in near blockchain through bigQuery?


I am doing a project to collect all validators in near blockchain. Is it a way to get all the validators in near blockchain through big query? Or any others way can done it?

That is expected to Get all validators and related information. Thank you.


Solution

  • About BigQuery

    It's unclear what you mean by "and related information", though.

    NEAR Protocol's BigQuery doesn't have a dedicated table about validators. However, if you're interested in collecting data around the pool contracts (*.poolv1.near), here's how you can start this journey:

    SELECT * FROM accounts WHERE account_id LIKE %.poolv1.near; 
    

    Then, you can join other tables with the information you need.

    Getting validators

    The best place to get the validators is the validators JSON RPC method (doc: https://docs.near.org/api/rpc/network#validation-status)

    Example getting current validators (using HTTPie)

    http post https://rpc.mainnet.near.org/ jsonrpc=2.0 id=qwe method=validators params:='[null]'
    

    This will give you something like this

    {
        "jsonrpc": "2.0",
        "result": {
            "current_fishermen": [],
            "current_proposals": [
                {
                    "account_id": "01node.poolv1.near",
                    "public_key": "ed25519:5xz7EbcnPqabwoFezdJBxieK8S7XLsdHHuLwM4vLLhFt",
                    "stake": "2651785850836414850874562538855",
                    "validator_stake_struct_version": "V1"
                },
                {
                    "account_id": "08investinwomen_runbybisontrails.poolv1.near",
                    "public_key": "ed25519:C6yqxQ3suwjmm8ufG5e3BsHiwxUs9h839FCneF41V7TM",
                    "stake": "1259312194385531417616801088112",
                    "validator_stake_struct_version": "V1"
                },
                ...
            ],
            "current_validators": [
                {
                    "account_id": "astro-stakers.poolv1.near",
                    "is_slashed": false,
                    "num_expected_blocks": 52,
                    "num_expected_chunks": 381,
                    "num_expected_chunks_per_shard": [
                        381
                    ],
                    "num_produced_blocks": 52,
                    "num_produced_chunks": 381,
                    "num_produced_chunks_per_shard": [
                        381
                    ],
                    "public_key": "ed25519:2nPSBCzjqikgwrqUMcuEVReJhmkC91eqJGPGqH9sZc28",
                    "shards": [
                        0
                    ],
                    "stake": "30742684328491423698599799364948"
                },
                {
                    "account_id": "bisontrails2.poolv1.near",
                    "is_slashed": false,
                    "num_expected_blocks": 65,
                    "num_expected_chunks": 342,
                    "num_expected_chunks_per_shard": [
                        342
                    ],
                    "num_produced_blocks": 65,
                    "num_produced_chunks": 340,
                    "num_produced_chunks_per_shard": [
                        340
                    ],
                    "public_key": "ed25519:BrLmFJArKkLWK1A4BumfnDGYrfaQ53H7YEPxWmqJ4bgA",
                    "shards": [
                        1
                    ],
                    "stake": "30658259138913505063339221593926"
                },
                ...
            ],
            "epoch_height": 2517,
            "epoch_start_height": 118554708,
            "next_fishermen": [],
            "next_validators": [
                {
                    "account_id": "astro-stakers.poolv1.near",
                    "public_key": "ed25519:2nPSBCzjqikgwrqUMcuEVReJhmkC91eqJGPGqH9sZc28",
                    "shards": [
                        0
                    ],
                    "stake": "30743491743415546763909410403374"
                },
                {
                    "account_id": "bisontrails2.poolv1.near",
                    "public_key": "ed25519:BrLmFJArKkLWK1A4BumfnDGYrfaQ53H7YEPxWmqJ4bgA",
                    "shards": [
                        1
                    ],
                    "stake": "30659446276155966832700815611142"
                },
                ...
            ],
            "prev_epoch_kickout": [
                {
                    "account_id": "bitmanna.poolv1.near",
                    "reason": {
                        "NotEnoughChunks": {
                            "expected": 13,
                            "produced": 0
                        }
                    }
                },
                {
                    "account_id": "ifedi.poolv1.near",
                    "reason": {
                        "NotEnoughChunks": {
                            "expected": 26,
                            "produced": 0
                        }
                    }
                },
                ...
            ]
        },
        "id": "qwe"
    }
    

    Here, you can dig through the data and get the data relevant to your case.

    Alternative

    I suspect you seek the data that Nearblocks.io API provides, including the URLs, descriptions of the validators, etc.

    /v1/validators endpoint.