Skip to content

Instantly share code, notes, and snippets.

@PrathamRawat

PrathamRawat/bakerQuery.js Secret

Created May 21, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.