How to implement ICP convert cycles and top-up programmatically

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?

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

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

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

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

Similar thread for JavaScript: How do i programmatically convert ICP to cycles?

You implement this in your canister:

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.

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.

Hi @haida :waving_hand:

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.

If you want automated, easily configurable cycle topups with email alerts, monitoring, and a full transaction history that’s what CycleOps does :eye_in_speech_bubble:

1 Like

Thanks, this is very good!