-
-
Save PrathamRawat/cb40f54127e44acd506681de9aacaca3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const conseilServer = { | |
| url: 'https://conseil-prod.cryptonomic-infra.tech:443', | |
| apiKey: "INSERT YOUR API KEY HERE", //Replace this with your own key from Nautilus Cloud | |
| network: 'mainnet' | |
| }; | |
| // Bakers by Balance Query | |
| let query = conseiljs.ConseilQueryBuilder.blankQuery(); // Initializes a blank query | |
| query = conseiljs.ConseilQueryBuilder.addFields(query, 'baker'); // Add the baker who baked the block as a field | |
| query = conseiljs.ConseilQueryBuilder.addFields(query, 'hash'); // Add the hash of the block as a field (to use to aggregate) | |
| query = conseiljs.ConseilQueryBuilder.addPredicate(query, 'timestamp', conseiljs.ConseilOperator.AFTER, [0]); // Add a date limit (0 for all time) | |
| query = conseiljs.ConseilQueryBuilder.addAggregationFunction(query, "hash", conseiljs.ConseilFunction.count); // Add an aggregation to count all of the block hashes a baker has baked | |
| query = conseiljs.ConseilQueryBuilder.addOrdering(query, "count_hash", conseiljs.ConseilSortDirection.DESC); // Order the results by descending order by the number of blocks each bakers has baked | |
| query = conseiljs.ConseilQueryBuilder.setLimit(query, 20); // Limits the results to 20 bakers | |
| // Wrapper function for query execution | |
| let execute = async function(query, entity) { | |
| let result = await conseiljs.ConseilDataClient.executeEntityQuery(conseilServer, 'tezos', conseilServer.network, entity, query); // ConseilJS call to execute query | |
| console.log(result) | |
| return result | |
| } | |
| result = execute(query, "blocks") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment