Skip to content

Instantly share code, notes, and snippets.

@PrathamRawat
Created May 21, 2020 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PrathamRawat/846bc9d56975b8196d66f879fa299d1a to your computer and use it in GitHub Desktop.
Save PrathamRawat/846bc9d56975b8196d66f879fa299d1a to your computer and use it in GitHub Desktop.
// Conseil Config Storage
const conseilServer = {
url: 'https://conseil-dev.cryptonomic-infra.tech:443',
apiKey: "YOUR KEYS HERE", //Replace this with your own API key from Nautilus Cloud
network: 'carthagenet'
};
// URL of the Cryptonomic Hosted Tezos Node
const tezosNode = "https://tezos-dev.cryptonomic-infra.tech:443";
// This is downloaded from the testnet faucet, you should replace this with your downloaded file!
const faucetAccount = {
"mnemonic": [
"will",
"seven",
"dismiss",
"life",
"muscle",
"year",
"addict",
"manage",
"quit",
"liar",
"multiply",
"birth",
"peace",
"latin",
"void"
],
"secret": "2854bd3477278ab917acfadafd8187abdaff7679",
"amount": "30780498300",
"pkh": "tz1UjZX2xEAST1oZmsSY5HYqTgRRCgh66ga7",
"password": "gSazhmpfhw",
"email": "buyplvvp.wpkfzxtd@tezos.example.org"
};
// This construct stores the keys for our downloaded account
const keystore = conseiljs.TezosWalletUtil.unlockFundraiserIdentity(
faucetAccount.mnemonic.join(' '),
faucetAccount.email,
faucetAccount.password,
faucetAccount.pkh
);
// This sends an account activation operation to the Tezos Node
let activationResult = conseiljs.TezosNodeWriter.sendIdentityActivationOperation(
tezosNode,
keystore,
faucetAccount.secret
);
console.log(activationResult)
// This reveals the account's public key on the chain to be used to send and receive operations
let revelationResult = conseiljs.TezosNodeWriter.sendIdentityActivationOperation(
tezosNode,
keystore,
faucetAccount.secret
);
console.log(revelationResult)
// 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
}
// Call to wrapper function to execute query for top bakers by block
bakerQueryResult = execute(query, "blocks")
// Operation to delegate XTZ to the baker that has baked the most blocks
const delegationResult = conseiljs.TezosNodeWriter.sendDelegationOperation(
tezosNode,
keystore,
keystore.publicKeyHash,
bakerQueryResult[0].baker,
10000
);
console.log(delegationResult)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment