# How to query delegator info for stake pool from command line?

**URL:** https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859
**Category:** Operate a Stake Pool
**Created:** [29 June 2021 10:40 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859 "2021-06-29T10:40:13Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![winthefee](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/winthefee/32/38384_2.png) [@winthefee](https://forum.cardano.org/u/winthefee)
#### Post date: [29 June 2021 10:40 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/1 "2021-06-29T10:40:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![shiferiz](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/shiferiz/32/70895_2.png) [@shiferiz](https://forum.cardano.org/u/shiferiz)
#### Post date: [10 September 2021 10:53 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/2 "2021-09-10T10:53:37Z")

</div>

I’m interested in this one as well

---

<div class="post-metadata">

### Author: ![Psychomb](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/psychomb/32/16719_2.png) [@Psychomb](https://forum.cardano.org/u/Psychomb)
#### Post date: [10 September 2021 10:55 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/3 "2021-09-10T10:55:34Z")

</div>

I would advise you to check out [blockfrost.io](http://blockfrost.io). They offer a free plan that will help you do what you want, quite easily.

---

<div class="post-metadata">

### Author: ![cyberruss](https://avatars.discourse-cdn.com/v4/letter/c/4bbf92/32.png) [@cyberruss](https://forum.cardano.org/u/cyberruss)
#### Post date: [11 September 2021 22:09 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/4 "2021-09-11T22:09:38Z")

</div>

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](https://adavault.com) plus some other data from coin gecko, and cncli. Happy to share how.

---

<div class="post-metadata">

### Author: ![crypto\_proun](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/crypto_proun/32/53549_2.png) [@crypto\_proun](https://forum.cardano.org/u/crypto_proun)
#### Post date: [12 May 2022 17:40 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/5 "2022-05-12T17:40:35Z")

</div>

Hey @cyberruss How do you do it ? Thanks

---

<div class="post-metadata">

### Author: ![HeptaSean](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/heptasean/32/82306_2.png) [@HeptaSean](https://forum.cardano.org/u/HeptaSean)
#### Post date: [12 May 2022 18:00 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/6 "2022-05-12T18:00:06Z")

</div>

You could also use [https://api.koios.rest/](https://api.koios.rest/):

```nohighlight
$ curl "https://api.koios.rest/api/v0/pool_delegators?_pool_bech32=pool1qqenhz258k5k9nyjull6gkzg7s4f3ae8v7qxwpegeef9v0nsy3e&_epoch_no=336"
[{"stake_address":"stake1u8792yuvwnqt5nwsepvkdlswhvfd8vk2ewr8jx3p2sd9vvq4c2ga4","amount":"2355006753647","epoch_no":336},
 {"stake_address":"stake1u9dm6wq6vee44c24qjwquqat4gypl9st6prh60t70zswdug8470jw","amount":"1402452321963","epoch_no":336},
 {"stake_address":"stake1uy04h2grcf84663cxwntrxnk0empdv0f98ugqmyt9z07cfgzxpt0h","amount":"556849187620","epoch_no":336},
…

```

The epoch number is optional:

```nohighlight
$ curl "https://api.koios.rest/api/v0/pool_delegators?_pool_bech32=pool1qqenhz258k5k9nyjull6gkzg7s4f3ae8v7qxwpegeef9v0nsy3e"
[{"stake_address":"stake1u9dm6wq6vee44c24qjwquqat4gypl9st6prh60t70zswdug8470jw","amount":"1405976018602","epoch_no":338},
 {"stake_address":"stake1uy04h2grcf84663cxwntrxnk0empdv0f98ugqmyt9z07cfgzxpt0h","amount":"558248285169","epoch_no":338},
 {"stake_address":"stake1uxrkfrnc79fu5jhyujsr66wqgzdy9d9zm0hu7qev8rsewyc2u4axc","amount":"426635022711","epoch_no":338},
…

```

---

<div class="post-metadata">

### Author: ![crypto\_proun](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/crypto_proun/32/53549_2.png) [@crypto\_proun](https://forum.cardano.org/u/crypto_proun)
#### Post date: [12 May 2022 18:12 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/7 "2022-05-12T18:12:18Z")

</div>

@HeptaSean im using code from api blockfrost curl -H “project\_id: mainne” [https://cardano-mainnet.blockfrost.io/api/v0/pools/poolid/delegators/](https://cardano-mainnet.blockfrost.io/api/v0/pools/poolid/delegators/) --output delegs.json

but only shows the stake address any chance that could show the full address?

---

<div class="post-metadata">

### Author: ![HeptaSean](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/heptasean/32/82306_2.png) [@HeptaSean](https://forum.cardano.org/u/HeptaSean)
#### Post date: [12 May 2022 18:15 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/8 "2022-05-12T18:15:58Z")

</div>

> [@crypto\_proun](#):
>
> but only shows the stake address any chance that could show the full address?

You can use [https://docs.blockfrost.io/#tag/Cardano-Accounts/paths/~1accounts~1{stake\_address}~1addresses/get](https://docs.blockfrost.io/#tag/Cardano-Accounts/paths/~1accounts~1%7Bstake_address%7D~1addresses/get) to get all addresses for a stake address.

There is not really _the_ full address except if you are using single address apps like Nami or CNTOOLS.

---

<div class="post-metadata">

### Author: ![crypto\_proun](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/crypto_proun/32/53549_2.png) [@crypto\_proun](https://forum.cardano.org/u/crypto_proun)
#### Post date: [12 May 2022 19:01 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/9 "2022-05-12T19:01:21Z")

</div>

@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?

thanks for your help!

---

<div class="post-metadata">

### Author: ![HeptaSean](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/heptasean/32/82306_2.png) [@HeptaSean](https://forum.cardano.org/u/HeptaSean)
#### Post date: [12 May 2022 19:05 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/10 "2022-05-12T19:05:09Z")

</div>

> [@crypto\_proun](#):
>
> can i use this code for more than one stake adress at the same time?

No, unfortunately not. That may cost some requests. Or you switch to identifying wallets/accounts/users by stake address instead of full address.

---

<div class="post-metadata">

### Author: ![crypto\_proun](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/crypto_proun/32/53549_2.png) [@crypto\_proun](https://forum.cardano.org/u/crypto_proun)
#### Post date: [12 May 2022 19:11 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/11 "2022-05-12T19:11:48Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![HeptaSean](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/heptasean/32/82306_2.png) [@HeptaSean](https://forum.cardano.org/u/HeptaSean)
#### Post date: [12 May 2022 19:19 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/12 "2022-05-12T19:19:11Z")

</div>

> [@crypto\_proun](#):
>
> so mostly every epoch pool operators that send air drops for the delegators wallets , seek one by one from the stake address?

Ah, if that is the use case, you could just cache the stake address – receive address association in a database.

> [@crypto\_proun](#):
>
> 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?

The rewards for the delegators and the pool are both distributed automatically by the protocol to the corresponding stake addresses.

So, the pool does not have to do anything to distribute them to the delegators.

---

<div class="post-metadata">

### Author: ![crypto\_proun](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/crypto_proun/32/53549_2.png) [@crypto\_proun](https://forum.cardano.org/u/crypto_proun)
#### Post date: [12 May 2022 19:21 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/13 "2022-05-12T19:21:51Z")

</div>

Ah, if that is the use case, you could just cache the stake address – receive address association in a database.

How can i do that ? 😃 😃

---

<div class="post-metadata">

### Author: ![HeptaSean](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/heptasean/32/82306_2.png) [@HeptaSean](https://forum.cardano.org/u/HeptaSean)
#### Post date: [12 May 2022 19:58 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/14 "2022-05-12T19:58:15Z")

</div>

> [@crypto\_proun](#):
>
> How can i do that ?

Oh, I just assumed that you were already doing that in some programming language.

Do you know/like one?

---

<div class="post-metadata">

### Author: ![crypto\_proun](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/crypto_proun/32/53549_2.png) [@crypto\_proun](https://forum.cardano.org/u/crypto_proun)
#### Post date: [12 May 2022 20:25 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/15 "2022-05-12T20:25:29Z")

</div>

not realy , there is a easy way to do it , maybe i can folow some walkthrough

---

<div class="post-metadata">

### Author: ![HeptaSean](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/heptasean/32/82306_2.png) [@HeptaSean](https://forum.cardano.org/u/HeptaSean)
#### Post date: [12 May 2022 22:48 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/16 "2022-05-12T22:48:17Z")

</div>

You could try this script:

```auto
#!/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.

---

<div class="post-metadata">

### Author: ![crypto\_proun](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/crypto_proun/32/53549_2.png) [@crypto\_proun](https://forum.cardano.org/u/crypto_proun)
#### Post date: [13 May 2022 12:45 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/17 "2022-05-13T12:45:58Z")

</div>

Thanks @HeptaSean ,Worked Great .

---

<div class="post-metadata">

### Author: ![HeptaSean](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/heptasean/32/82306_2.png) [@HeptaSean](https://forum.cardano.org/u/HeptaSean)
#### Post date: [13 May 2022 12:49 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/18 "2022-05-13T12:49:38Z")

</div>

Glad it helped!

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.

---

<div class="post-metadata">

### Author: ![crypto\_proun](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/crypto_proun/32/53549_2.png) [@crypto\_proun](https://forum.cardano.org/u/crypto_proun)
#### Post date: [13 May 2022 14:06 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/19 "2022-05-13T14:06:19Z")

</div>

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 ?

---

<div class="post-metadata">

### Author: ![crypto\_proun](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/crypto_proun/32/53549_2.png) [@crypto\_proun](https://forum.cardano.org/u/crypto_proun)
#### Post date: [13 May 2022 18:14 UTC](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859/20 "2022-05-13T18:14:16Z")

</div>

@HeptaSean Hey , is there a way to modify this code to see in those address if they have a nft in it and how many? maybe using the code [https://cardano-mainnet.blockfrost.io/api/v0/assets/{asset}/addresses](https://cardano-mainnet.blockfrost.io/api/v0/assets/%7Basset%7D/addresses) , and also how much adas each have staked ? Thanks!

[Next page](https://forum.cardano.org/t/how-to-query-delegator-info-for-stake-pool-from-command-line/65859.md?page=2)
