# Candid::nat to u128

**URL:** <https://forum.dfinity.org/t/candid-nat-to-u128/16016>\
**Category:** Rust\
**Created:** [October 20, 2022, 3:51pm UTC](https://forum.dfinity.org/t/candid-nat-to-u128/16016 "2022-10-20T15:51:20Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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 22, 2022, 6:36am UTC](https://forum.dfinity.org/t/candid-nat-to-u128/16016/3 "2022-10-22T06:36:33Z")

</div>

Thanks for the solution and explanation @AdamS, it did the job.

`canister_balance128` is also a good tips, I’ll use it. I was using `canister_status` because I am still hoping that somewhere there is an information about the [minimal amount of cycles to retain before deleting a canister](https://forum.dfinity.org/t/minimal-cycles-to-delete-canister/15926/2).

If it can be useful in the future for anyone landing on this, here the implementation of above elements:

```auto
use ic_cdk::api::management_canister::main::{ CanisterIdRecord, deposit_cycles };
use ic_cdk::api::{ canister_balance128 };

#[update]
async fn transfer_cycles() {
    // TODO: determine effective threshold - how few cycles should be retained before deleting the canister?
    // use freezing_threshold_in_cycles? - https://github.com/dfinity/interface-spec/pull/18/files
    // actually above PR was ultimately deleted? - https://forum.dfinity.org/t/minimal-cycles-to-delete-canister/15926

    // Source: https://forum.dfinity.org/t/candid-nat-to-u128/16016
    let balance: u128 = canister_balance128();
    let cycles: u128 = balance - 100_000_000_000u128;

    if cycles > 0 {
        let arg_deposit = CanisterIdRecord { canister_id: caller };
        deposit_cycles(arg_deposit, cycles).await.unwrap();
    }
}

```

---

_[View the full topic](https://forum.dfinity.org/t/candid-nat-to-u128/16016)._
