# How to implement ICP convert cycles and top-up programmatically

**URL:** <https://forum.dfinity.org/t/how-to-implement-icp-convert-cycles-and-top-up-programmatically/43183>\
**Category:** Language Support\
**Tags:** Motoko\
**Created:** [March 31, 2025, 1:26am UTC](https://forum.dfinity.org/t/how-to-implement-icp-convert-cycles-and-top-up-programmatically/43183 "2025-03-31T01:26:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![haida](https://avatars.discourse-cdn.com/v4/letter/h/d9b06d/32.png) [@haida](https://forum.dfinity.org/u/haida)\
**Post date:** [March 31, 2025, 1:26am UTC](https://forum.dfinity.org/t/how-to-implement-icp-convert-cycles-and-top-up-programmatically/43183/1 "2025-03-31T01:26:43Z")

</div>

```auto
dfx cycles convert
dfx cycles top-up

```

We currently use the above commands to handle cycles conversion and recharge.  
Is it possible to implement these functions through coding for automation?

> **[GitHub - CycleOperators/cycles-manager: A library for managing cycles across hundreds of...](https://github.com/CycleOperators/cycles-manager)**
>
> A library for managing cycles across hundreds of canisters.

The ICP convert cycles code was not found in this open source example.

The links to the related questions in the forum have expired, and no valid examples have been found.

We found through transaction tracking that our ICP is processing conversion and burning through this address  
[https://dashboard.internetcomputer.org/account/862c5b6302da1e2ad3c18340cef2f7f608e971120fd311a29ad50ac6b62226f5](https://dashboard.internetcomputer.org/account/862c5b6302da1e2ad3c18340cef2f7f608e971120fd311a29ad50ac6b62226f5)

Or is there a simple way to directly transfer ICP to an address or other forms, and then automatically canister top-up cycles

> **[Topping up a canister | Internet Computer](https://internetcomputer.org/docs/building-apps/canister-management/topping-up)**
>
> A canister needs to have cycles deposited continuously into it to pay for the resources it uses. This process is known as 'topping up' the canister. Topping up canisters is routine maintenance.

Here we have seen, but there is no encoding method, mainly ICP convert cycles

---

<div class="post-metadata">

**Author:** ![fochive00](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@fochive00](https://forum.dfinity.org/u/fochive00)\
**Post date:** [March 31, 2025, 1:36am UTC](https://forum.dfinity.org/t/how-to-implement-icp-convert-cycles-and-top-up-programmatically/43183/2 "2025-03-31T01:36:44Z")

</div>

**Juno** should have this feature. @peterparker might be able help you with it.

---

<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:** [March 31, 2025, 4:18am UTC](https://forum.dfinity.org/t/how-to-implement-icp-convert-cycles-and-top-up-programmatically/43183/3 "2025-03-31T04:18:08Z")

</div>

Similar thread for JavaScript: [How do i programmatically convert ICP to cycles?](https://forum.dfinity.org/t/how-do-i-programmatically-convert-icp-to-cycles/14035)

---

<div class="post-metadata">

**Author:** ![saikatdas0790](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/saikatdas0790/32/17147_2.png) [@saikatdas0790](https://forum.dfinity.org/u/saikatdas0790)\
**Post date:** [March 31, 2025, 4:35am UTC](https://forum.dfinity.org/t/how-to-implement-icp-convert-cycles-and-top-up-programmatically/43183/4 "2025-03-31T04:35:33Z")

</div>

You implement this in your canister:

> **[GitHub - dfinity/canfund: Library for automated cycles management of...](https://github.com/dfinity/canfund)**
>
> Library for automated cycles management of canisters on the Internet Computer

It’s Rust only though, so, Motoko will need their own solution

This is a stop gap solution though till we have canister hooks, in which case, a canister will have a “cycles below threshold” hook that can just call into a callback function to top it up. That callback function can have additional logic for authorization, logging, metrics, etc.

---

<div class="post-metadata">

**Author:** ![haida](https://avatars.discourse-cdn.com/v4/letter/h/d9b06d/32.png) [@haida](https://forum.dfinity.org/u/haida)\
**Post date:** [March 31, 2025, 1:08pm UTC](https://forum.dfinity.org/t/how-to-implement-icp-convert-cycles-and-top-up-programmatically/43183/5 "2025-03-31T13:08:14Z")

</div>

`dfx cycles convert ICP` ，I have not found any valid examples or APIs for this command.

I don’t know if there are any effective examples or guides for motoko or js. Rust is too unfamiliar to me.

---

<div class="post-metadata">

**Author:** ![icme](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icme/32/4327_2.png) [@icme](https://forum.dfinity.org/u/icme)\
**Post date:** [April 1, 2025, 3:19am UTC](https://forum.dfinity.org/t/how-to-implement-icp-convert-cycles-and-top-up-programmatically/43183/6 "2025-04-01T03:19:50Z")

</div>

Hi @haida 👋

If you’re looking for a library that you can use from an agent, we built the icptopup-ts library that provides atomic topups of up to 100 canisters at a time.

> [@man\_technologist icptopup-ts: atomic, ICRC compatible batch cycles topups with TypeScript](https://forum.dfinity.org/t/icptopup-ts-atomic-icrc-compatible-batch-cycles-topups-with-typescript/41340):
>
> Today the CycleOps team eye is releasing [icptopup-ts](https://github.com/CycleOperators/icptopup-ts), a TypeScript package that makes it easy to programatically man_technologist facilitate large amounts of decentralized compute, sending cycles to up to 100 canisters at at time. With npm install icptopup-ts, you can integrate atomic, ICRC compatible cycle topups into your application in just a few minutes hourglass_flowing_sandHow can I use icptopup-ts?point_right &nbsp; Get started with the icptopup-ts [installation ins…](https://github.com/CycleOperators/icptopup-ts)

If you want automated, easily configurable cycle topups with email alerts, monitoring, and a full transaction history that’s what [CycleOps](https://forum.dfinity.org/t/meet-cycleops-proactive-automated-no-code-canister-management-for-the-internet-computer/20969) does 👁️‍🗨️

---

<div class="post-metadata">

**Author:** ![haida](https://avatars.discourse-cdn.com/v4/letter/h/d9b06d/32.png) [@haida](https://forum.dfinity.org/u/haida)\
**Post date:** [April 2, 2025, 8:22am UTC](https://forum.dfinity.org/t/how-to-implement-icp-convert-cycles-and-top-up-programmatically/43183/7 "2025-04-02T08:22:10Z")

</div>

Thanks, this is very good!
