Management_canister - install_code - out of cycles

I am studying management_canister.

let foobar = install_code(install_code_arg).await.unwrap();

I get an error with install_code. I am running locally, not on mainnet. I would like to get rid of the error.

Reject text: Canister rno2w-sqaaa-aaaaa-aaacq-cai trapped explicitly: Panicked at ‘called Result::unwrap() on an Err value: (CanisterError, “Canister installation failed with Canister q3fc5-haaaa-aaaaa-aaahq-cai is out of cycles: requested 80000590000 cycles but the available balance is 0 cycles and the freezing threshold 11827 cycles”)’, src/management_canister_study_backend/src/

use ic_cdk::*;
use ic_cdk::api::management_canister::main::*;

async fn create_canister_example() {
    let create_canister_arg = CreateCanisterArgument {
        settings: Some(CanisterSettings {
            controllers: Some(vec![ic_cdk::id()]),
            compute_allocation: Some(0.into()),
            memory_allocation: Some(10000.into()),
            freezing_threshold: Some(10000.into()),
    let canister_id_records = create_canister(create_canister_arg).await.unwrap();
    let canister_id_record = canister_id_records.0;
    let canister_id = canister_id_record.canister_id;

    let install_code_arg = InstallCodeArgument {
        mode: CanisterInstallMode::Install,
        wasm_module: b"\x00asm\x01\x00\x00\x00".to_vec(),
        arg: vec![],
    let foobar = install_code(install_code_arg).await.unwrap();
1 Like

Installing code into a canister requires cycles. Apparently you created your canister with 0 cycles. If I’d guess how it happened: You did dfx canister create --with-cycles <0.1 Trillion>. Creation of the canister costs 0.1T, which leaves 0 cycles for the canister itself.

Local remediation: dfx ledger fabricate-cycles <cycles> <canister>
Mainnet: dfx canister deposit-cycles <cycles> <canister>


Thank you! I was able to resolve the error.

1 Like