Skip to content

Instantly share code, notes, and snippets.

Created May 21, 2020
What would you like to do?
const conseilServer = {
url: '',
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',, entity, query); // ConseilJS call to execute query
return result
result = execute(query, "blocks")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment