Dfx deploy to IC error when creating canister

Our dapp works fine locally but shows the following error when deploying to IC. (I have followed the steps outlined in Hamish Peebles’ recent hackathon presentation to assign some ICP for transaction fees and create the canister.) The ledger balance has reverted to zero.

Any help greatly appreciated.
Thanks
Dave

simplifire-ic $ dfx ledger --network ic balance
0.10000000 ICP
simplifire-ic $ dfx identity get-principal
vndxw-adddz-5ef67-fgcv4-fn45z-guful-2qih7-dte3j-pq24k-3oogf-mqe
simplifire-ic $ dfx ledger --network ic create-canister --amount 0.0998 vndxw-adddz-5ef67-fgcv4-fn45z-guful-2qih7-dte3j-pq24k-3oogf-mqe
Transfer sent at BlockHeight: 3329631
Canister created with id: "5noxm-hqaaa-aaaao-aabvq-cai"
simplifire-ic $ dfx deploy --network ic --no-wallet rust_simplifire
Deploying: rust_simplifire
Creating canisters...
Creating canister "rust_simplifire"...
Error: The replica returned an HTTP Error: Http Error: status 404 Not Found, content type "text/html", content: <html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.21.3</center>
</body>
</html>

simplifire-ic $ dfx ledger --network ic balance
0.00000000 ICP

The error message (almost certainly) means that you do not have a wallet set for your identity (dfx identity --network ic get-wallet fails). A better error message will be printed once the next dfx release hits.

What happened here:

  • You created a canister with id 5noxm-hqaaa-aaaao-aabvq-cai
  • You tried to deploy the rust_simplifire canister.
  • dfx does not know that 5noxm-hqaaa-aaaao-aabvq-cai is supposed to be rust_simplifire
  • dfx tries to create a new canister using the configured cycles wallet
  • Wallet is not configured, so an error 404 occurs. (In the next version of dfx this will give an error similar to Error: Could not find wallet for "default" on "ic" network.)

First off, if you want to configure a cycles wallet, please follow the quick start guide. Second, to associate the canister id 5noxm-hqaaa-aaaao-aabvq-cai with the alias rust_simplifire, you have to add it to canister_ids.json, which should be right next to dfx.json:

{
  "rust_simplifire": {
    "ic": "5noxm-hqaaa-aaaao-aabvq-cai"
  }
}

To see a live example of canister_ids.json, have a look at the canister_ids of internet identity.

Side note: the --no-wallet flag is not necessary anymore if you’re on the latest dfx version (0.9.3). If you get 403 forbidden after the upgrade, please follow the steps in Troubleshooting step 3

Thanks so much, Severin, for the swift reply.

I followed the quick start guide as you suggested and obtained cycles from the faucet as follows:

simplifire-ic $ dfx identity --network=ic set-wallet oqlxq-pqaaa-aaaal-qawiq-cai
Setting wallet for identity 'default' on network 'ic' to id 'oqlxq-pqaaa-aaaal-qawiq-cai'
Wallet set successfully.
simplifire-ic $ dfx wallet --network=ic balance
899985838644 cycles.

However, this. number of cycles appears to be insufficient to create the canister:

simplifire-ic $ dfx deploy --network ic rust_simplifire         
Deploying: rust_simplifire
Creating canisters...
Creating canister "rust_simplifire"...
Error: The Replica returned an error: code 5, message: "Canister oqlxq-pqaaa-aaaal-qawiq-cai is out of cycles: requested 4000000000000 cycles but the available balance is 897983612159 cycles and the freezing threshold 862181998 cycles"

Do I need to top it up with more cycles from my NNS account?
(BTW, I am on dfx version 0.9.2 but it did work without the --no-wallet flag.)

Yeah, looks like it. The faucet sometimes runs low and we don’t have it automatically filling up at the moment… :frowning_face:

Oh, by the way, you can easily try to create the canister with less cycles using the --with-cycles flag. Just bear in mind that merely creating a canister already costs 1T cycles. Beyond that you don’t need too many. 0.3T should already be enough for a hello world thingy

1 Like

I ran into this issue a few days ago, you actually have enough cycles, you just need to specify how many cycles you want to deploy your app with

dfx deploy --network ic <your_canister_name> --with-cycles 300000000000

If you’ve already deployed your app but the canister is out of cycles, you may receive this message:

Error: The replica returned an HTTP Error: Http Error: status 503 Service Unavailable, content type "application/cbor", content: Canister <your_canister_id>: requested 524714000 cycles but the available balance is 0 cycles and the freezing threshold 0 cycles

In this case you need to use the deposit-cycles command to top your canister up.

dfx canister --network=ic --wallet=<your_wallet_id> deposit-cycles 200000000000 <your_canister_id>

@Severin I think the documentation could use an update :slight_smile:

Thanks, icme. Tried this and got a new error message. (Noting also that the wallet balance has been reduced.)

Deploying: rust_simplifire
Creating canisters...
Creating canister "rust_simplifire"...
"rust_simplifire" canister created on network "ic" with canister id: "ompnb-yqaaa-aaaal-qawkq-cai"
Building canisters...
Executing: cargo build --target wasm32-unknown-unknown --release -p rust_simplifire
warning: unused import: `ic_cdk::storage`
  -->  [... couple of Rust compile warnings here ...]
warning: `rust_simplifire` (lib) generated 2 warnings
    Finished release [optimized] target(s) in 0.19s
Executing: ic-cdk-optimizer -o target/wasm32-unknown-unknown/release/rust_simplifire.wasm target/wasm32-unknown-unknown/release/rust_simplifire.wasm
Installing canisters...
Installing code for canister rust_simplifire, with canister_id ompnb-yqaaa-aaaal-qawkq-cai
Error: The replica returned an HTTP Error: Http Error: status 413 Payload Too Large, content type "application/cbor", content: Request 0xb1636663f1bab8bd420c0478e6904279506301cb76661ffcbd9a6bc396a51b51 is too large. Message byte size 2318830 is larger than the max allowed 2097152.
simplifire-ic $ dfx wallet --network=ic balance                                   
599974088741 cycles.

Any thoughts? Or should I just beef up the canister wallet for more cycles (I have 0.9 ICP sitting in my NNS wallet).

Don’t quote me on this since I’m not an expert, but it looks to me like this isn’t a cycles issue any more. If you read the error message it looks like the wasm your trying to deploy to your canister is too large (by roughly 310KB).

Yes, @icme is right. I don’t know anything about minimising the wasm size, but I think if you go here Smart Contracts on the Internet Computer you can find a few ideas to try.

I know, I know… I’m annoyed at our documentation on a daily basis. So many things to do.

1 Like

Hi @Severin, @icme I minimised the wasm size following the instructions on DFinity page Optimize a Rust program :: Internet Computer. But the ‘Payload too large’ error still comes up. Any thoughts? I had also tried reducing the lines of code in the Rust source (hence the warnings).

simplifire-ic $ ic-cdk-optimizer target/wasm32-unknown-unknown/release/rust_simplifire.wasm -o target/wasm32-unknown-unknown/release/rust_simplifire-opt.wasm
Original:          2.17 MiB
Stripping Unused Data Segments...
    Size:          558.30 KiB (74.9% smaller)
Execute a binaryen optimization pass on your WASM....
    Size:          502.55 KiB (10.0% smaller)

Final Size: 502.55 KiB (77.4% smaller)
simplifire-ic $ dfx deploy --network ic rust_simplifire --with-cycles 300000000000
Deploying: rust_simplifire
All canisters have already been created.
Building canisters...
Executing: cargo build --target wasm32-unknown-unknown --release -p rust_simplifire
warning: unused import: `ic_cdk::storage`
  --> src/rust_simplifire/lib.rs:10:5
   |
10 | use ic_cdk::storage; // Profile example
   |     ^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: type alias is never used: `IdStore`
  --> src/rust_simplifire/lib.rs:32:1
   |
32 | type IdStore = BTreeMap<String, Principal>;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: `rust_simplifire` (lib) generated 2 warnings
    Finished release [optimized] target(s) in 0.11s
Executing: ic-cdk-optimizer -o target/wasm32-unknown-unknown/release/rust_simplifire.wasm target/wasm32-unknown-unknown/release/rust_simplifire.wasm
Installing canisters...
Installing code for canister rust_simplifire, with canister_id ompnb-yqaaa-aaaal-qawkq-cai
Error: The replica returned an HTTP Error: Http Error: status 413 Payload Too Large, content type "application/cbor", content: Request 0xac434e26c521a2c18e2dc4403f2fa6e7ee7d096306eade1c7dd3ca4dfbfad1f3 is too large. Message byte size 2278387 is larger than the max allowed 2097152.

Again, not an expert (I have not run into this issue before, and develop in Motoko), but if you look at the logging you provided, your optimized wasm size is 500KB (less than the limit), and the wasm you’re trying to upload is still over 2MB.

Maybe try following the instructions in this thread - Http Error: status 413 Payload Too Large

1 Like

We solved this one by minimising the vue.js code with a webpack change. All the modules within a large template were being included so that the maximum size was exceeded.

Got some free cycles from the faucet and Simplifire-IC (version 0.1) is now running sweetly on the IC.