On Steem Blockchain, we can either proxy a witness vote or cast a witness vote (out of 30 votes) to a steem witness. We can use the steemjs library to get account information which includes the current proxy and the list of witness votes (up to 30):
function is_voted_by(witness, id) {
return new Promise((resolve, reject) => {
steem.api.getAccounts([id], function(err, response) {
if (err) reject(err);
if (typeof response == "undefined") reject("undefined");
const data = response[0];
resolve((data.proxy === witness) || data.witness_votes.includes(witness));
});
});
}
Testing to prove that it works:
(async function() {
const check_witness_vote = await is_voted_by("justyy", "ety001");
console.log(check_witness_vote); // true as @ety001 votes @justyy
const check_proxy_vote = await is_voted_by("justyy", "mrspointm");
console.log(check_proxy_vote ); // true as @mrspointm sets proxy to @justyy
})();
The is_voted_by returns a promise so that we can await on it.
The above NodeJs example runs in SteemJs Editor
Steem Programming
- Building a Reliable Witness Vote Checker for the Steem Blockchain (with Retry & Exponential Backoff)
- Javascript (NodeJS) Function to Check if a Witness Has been Voted by or Proxied By on Steem Blockchain
–EOF (The Ultimate Computing & Technology Blog) —
408 wordsLast Post: Teaching Kids Programming - Count Number of Pairs With Absolute Difference K
Next Post: Teaching Kids Programming - Final Value of Variable After Performing Operations (via Reduce Function)