# Get assets canister cycles balance

**URL:** <https://forum.dfinity.org/t/get-assets-canister-cycles-balance/8280>\
**Category:** Developers\
**Created:** [November 2, 2021, 9:43am UTC](https://forum.dfinity.org/t/get-assets-canister-cycles-balance/8280 "2021-11-02T09:43:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexeychirkov](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/alexeychirkov/32/1991_2.png) [@alexeychirkov](https://forum.dfinity.org/u/alexeychirkov)\
**Post date:** [November 2, 2021, 9:43am UTC](https://forum.dfinity.org/t/get-assets-canister-cycles-balance/8280/1 "2021-11-02T09:43:52Z")

</div>

Hello developers!

If there is a possibility to ask the asset canister ({“type”: “assets”} in dfx.json) for it’s cycles balance programmatically?

I would like to monitor cycles balance in Prometheus.  
Currently all my Motoko canisters has a public query method to return cycles using ExperimentalCycles module.  
Is there is a way to do it with asset canisters?

Only way I know is to get it using “dfx” command line.

I am thinking… I can fork “certified-assets” repo and add additional logic to it…

---

<div class="post-metadata">

**Author:** ![nomeata](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nomeata/32/733_2.png) [@nomeata](https://forum.dfinity.org/u/nomeata)\
**Post date:** [November 2, 2021, 10:32pm UTC](https://forum.dfinity.org/t/get-assets-canister-cycles-balance/8280/2 "2021-11-02T22:32:06Z")

</div>

For any canister you can add the [blackhole canister](https://github.com/ninegua/ic-blackhole) as an _additional_ controller and then anyone can query the cycle balance through that canister.

In fact, that should be considered best practice for anyone who don’t mind the public to see this data. And then pages like ic.rocks (pinging @wang) can display cycle balances, maybe even graph them over time…

---

<div class="post-metadata">

**Author:** ![rbole](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rbole/32/1334_2.png) [@rbole](https://forum.dfinity.org/u/rbole)\
**Post date:** [September 28, 2022, 11:08am UTC](https://forum.dfinity.org/t/get-assets-canister-cycles-balance/8280/3 "2022-09-28T11:08:59Z")

</div>

Is there any experience on this topic?

How we can monitor an asset canister without dfx command e.g.

> dfx wallet --network ic balance --precise

---

<div class="post-metadata">

**Author:** ![domwoe](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/domwoe/32/5165_2.png) [@domwoe](https://forum.dfinity.org/u/domwoe)\
**Post date:** [September 28, 2022, 11:37am UTC](https://forum.dfinity.org/t/get-assets-canister-cycles-balance/8280/4 "2022-09-28T11:37:43Z")

</div>

You need to make a call to the `canister_status` on the management canister with a caller that is listed as a controller of the respective canister.

Here @peterparker shared a snippet of how to do it using agent-js: [How to make IC Management API canister\_status call with @dfinity/agent?](https://forum.dfinity.org/t/how-to-make-ic-management-api-canister-status-call-with-dfinity-agent/7139)

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [September 28, 2022, 11:40am UTC](https://forum.dfinity.org/t/get-assets-canister-cycles-balance/8280/5 "2022-09-28T11:40:37Z")

</div>

I even build my self an open source monitoring dapp that supports NNS and SNS canisters 👉 [https://cycles.watch/](https://cycles.watch/)

---

<div class="post-metadata">

**Author:** ![rbole](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rbole/32/1334_2.png) [@rbole](https://forum.dfinity.org/u/rbole)\
**Post date:** [September 28, 2022, 12:43pm UTC](https://forum.dfinity.org/t/get-assets-canister-cycles-balance/8280/6 "2022-09-28T12:43:44Z")

</div>

Thank you very much, these are great examples. I will study it and try to build a nodejs script to fetch the balance.

---

<div class="post-metadata">

**Author:** ![cryptoschindler](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cryptoschindler/32/26_2.png) [@cryptoschindler](https://forum.dfinity.org/u/cryptoschindler)\
**Post date:** [September 29, 2022, 6:30am UTC](https://forum.dfinity.org/t/get-assets-canister-cycles-balance/8280/7 "2022-09-29T06:30:43Z")

</div>

If you are interested in automatically topping up your canisters, this is a really helpful tool

> [@Worry about your favorate canister running low on cycles? You got it covered!](https://forum.dfinity.org/t/worry-about-your-favorate-canister-running-low-on-cycles-you-got-it-covered/10307):
>
> Hi everyone! I’ve decided to beef up [my little ICP-to-cycle demo](https://forum.dfinity.org/t/sample-code-receiving-icp-cycles-donation/4752) back in the day. So please allow me to present to you the [Canister Tip Jar](https://github.com/ninegua/tipjar)! It allows anybody to choose and donate cycles to their favorite canisters, as long as the canister has [the black hole canister](https://forum.dfinity.org/t/introduce-the-black-hole-to-help-with-canister-status-lookup-make-them-immutable/5755) in its controller list. Cycles are not sent all at once though, they are only sent on a need basis – whenever a canister’s cycle runs below daily average, it will be topped up to the average again. The app is almost ready, but si…

---

<div class="post-metadata">

**Author:** ![rbole](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rbole/32/1334_2.png) [@rbole](https://forum.dfinity.org/u/rbole)\
**Post date:** [October 1, 2022, 2:20pm UTC](https://forum.dfinity.org/t/get-assets-canister-cycles-balance/8280/8 "2022-10-01T14:20:39Z")

</div>

I’m sorry I need more help on this topic. In your example, see link2, your actor is calling the method canister\_status.

> const response = await actor.canister\_status({  
> canister\_id: Principal.fromText(canisterId)  
> })

In my example I receive the following error:

> myAgent.canister\_status is not a function

I use the did.js file from the generated asset canister, but there is no service function canister\_status in.

How can I add this function ?? What I’m missing ?

I would very grateful for some light.

---

<div class="post-metadata">

**Author:** ![domwoe](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/domwoe/32/5165_2.png) [@domwoe](https://forum.dfinity.org/u/domwoe)\
**Post date:** [October 1, 2022, 3:48pm UTC](https://forum.dfinity.org/t/get-assets-canister-cycles-balance/8280/9 "2022-10-01T15:48:57Z")

</div>

Hey @rbole,

you need to call the [`canister_status` method of the “management canister”](https://github.com/dfinity/interface-spec/blob/f29fb083893c4d19de6373e1da6f74203a28679f/spec/ic.did#L101).

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [October 1, 2022, 4:08pm UTC](https://forum.dfinity.org/t/get-assets-canister-cycles-balance/8280/10 "2022-10-01T16:08:52Z")

</div>

It’s because in Papyrs I implement the canister status on the backend side while in Cycles.watch it’s on the frontend side 😜

* * *

If you want to do it on the backend side, and then expose it through a custom actor function, you can use `canister_status` basically summarized as following:

```auto
let ic = actor "aaaaa-aa";
await ic.canister_status({canister_id = canisterId});
// here expose the results you need through an actor function

```

Source: my [utils.mo](https://github.com/papyrs/ic/blob/97eeb34e6f2adc98d122f8100b50cbb2116521bd/canisters/src/utils/canister.utils.mo#L71) and [types.mo](https://github.com/papyrs/ic/blob/97eeb34e6f2adc98d122f8100b50cbb2116521bd/canisters/src/types/ic.types.mo#L30)

* * *

If you want to do it on the frontend side without exposing a custom function in your own canister you can also instantiate the IC and query directly the `canister_status`

```auto

const createICActor = (identity: Identity): Promise<ICActor> =>
  createActor<ICActor>({
    config: {
      canisterId: Principal.fromText('aaaaa-aa'),
      callTransform: transform,
      queryTransform: transform
    },
    idlFactory,
    identity
  });

const actor: ICActor = await createICActor(identity);

  const {cycles, status, memory_size} = await actor.canister_status({
    canister_id: Principal.fromText(canisterId)
  });

```

You just need a small transform function to convert the IC self canister id.

Source: function and actor in my cycles.watch [ic.services.ts](https://github.com/papyrs/cycles.watch/blob/503930f7d793533084665f2454772d50af82ade9/src/lib/services/ic.services.ts) and you also gonna need the ic [did](https://github.com/papyrs/cycles.watch/tree/503930f7d793533084665f2454772d50af82ade9/src/lib/canisters/ic) files

* * *

In both the ID to use to access the IC is `aaaaa-aa`.

Let me know if it works out.

* * *

Side note: in the [IC-js](https://github.com/dfinity/ic-js) repo we do have not yet implemented these functions for the IC but it’s totally the plan to add some soon
