I run a stake pool and am trying to figure out how I can query via command line who the current delegators are in the current epoch and how much active stake they each have.
Is this something I can do with cardano-cli? Or is there another commandline tool I can use?
I’m trying to automate a lottery function for the pool.
Agree on the Blockfrost suggestion. Very easy using curl to automate collection of stats and process using bash, or if you prefer nodejs so you can process the json output and use in your website…
We use them for ADAvault plus some other data from coin gecko, and cncli. Happy to share how.
@HeptaSean from that code i was abble to get the address i need but on at the time , can i use this code for more than one stake adress at the same time?
ok, @HeptaSean so mostly every epoch pool operators that send air drops for the delegators wallets , seek one by one from the stake address?
also quick question , the rewards for the delegators is send out automatically when the block is minted and only the pools owner reward that need to be retrived later for another wallet for exemple?
#!/bin/sh
# Things we need:
all_there=true
for cmd in curl jq awk
do
if ! command -v ${cmd} > /dev/null 2>&1
then
echo "Command ${cmd} is required. Please install."
all_there=false
fi
done
if [ "${all_there}" != true ]
then
exit 1
fi
if [ -z "${BLOCKFROST_PROJECT_ID}" ]
then
echo "BLOCKFROST_PROJECT_ID has to be set:"
echo " export BLOCKFROST_PROJECT_ID=\"mainnetXXXXX\""
exit 1
fi
if [ -z "${1}" ]
then
echo "First argument has to be the pool ID."
exit 1
fi
# Get stake addresses and put them in file stake_addresses:
curl -s -H "project_id: ${BLOCKFROST_PROJECT_ID}" \
https://cardano-mainnet.blockfrost.io/api/v0/pools/${1}/delegators | \
jq -r '.[] | .address' > stake_addresses
# Get receive addresses and put them in file stake_receive_addresses:
if [ -f stake_receive_addresses ]
then
mv stake_receive_addresses old_stake_receive_addresses
fi
while read stake_address
do
if ! grep "^${stake_address}" old_stake_receive_addresses 2> /dev/null
then
echo -n "${stake_address} "
curl -s -H "project_id: ${BLOCKFROST_PROJECT_ID}" \
https://cardano-mainnet.blockfrost.io/api/v0/accounts/${stake_address}/addresses | \
jq -r '.[0] | .address'
fi
done < stake_addresses > stake_receive_addresses
# Put just the receive addresses in file recevive_addresses:
awk '{print $2}' stake_receive_addresses > receive_addresses
As usual with scripts, put it in a text file, make it executable with chmod +x delegators.sh (or however you have called it) and then you can execute it by ./delegators.sh in the same directory, put it somewhere in your $PATH or whatever.
The script wants to have the Blockfrost project ID in an environment variable and the pool ID as first and only argument. It creates a bunch of files in the current directory: stake_addresses with only the stake addresses, stake_receive_addresses with both, stake and receive addresses, and receive_addresses with just the receive addresses.
If stake_receive_addresses is there from a previous run, the stake addresses are searched in that file with grep and curl to Blockfrost is only used if they are not found.
I’d normally do something like that in Python, but I hoped that a shell script is closer to what you already know and you can track what’s happening there.
Hey @HeptaSean Thank You. Do you know a way to distribute Native Tokens to Delegators? and there is a way to know from a script if those wallets have a specific NFT and how many of them, similar how hosky do it ?