Canister controller and cycle balance need to be public

For people who are willing to make cycle balance public through the black hole canister, you now can enjoy an automatic topup service too!

Please see Worry about your favorate canister running low on cycles? You got it covered!

4 Likes

Canister controllers and module hash is available through dfx using

❯ dfx canister --network ic info ivcos-eqaaa-aaaab-qablq-cai
Controllers: hgfyw-myaaa-aaaab-qaaoa-cai
Module hash: 0x2d8060fe316775976ad0a33975e846e98b649536be51c8bcf33a7c61806041c6

How to achieve same by using JavaScript?

1 Like

Also, by using nns/lifeline - rno2w-sqaaa-aaaaa-aaacq-cai canister and method canister_status we can get Canister’s controllers information as an error.

any other cleaner approach to get controllers and canister running status, module hash using js/httpAgent?

1 Like

dfx actually gets the controller and hash of a canister through read_state call. You can also do that using low level API calls using agent-js.

However, only a controller of a canister can get its cycle balance and other info. This means, unless a canister’s controller purposely decides to expose such info to the public, they will remain private information.

One way for a developer to voluntarily expose such data is to use the black hole canister, simplying by adding the black hole canister id as one of the controllers of your own canister. Then others can send an update call canister_status to the black hole canister to get all status info including remaining cycle balance. It is useful and safe because the black hole canister itself is immutable. I also built a TipJar service to help monitor canister cycle balance and top up them when they run low, and of course, only those with blackhole as one of their controllers are supported.

3 Likes