How to upload files to an existing canister?

Hi,

I’m having trouble getting files from my computer into a canister I created.

I created a canister and funded it already via the NNS, on the web.

I created a developer account on my computer.

I installed the IC SDK on my computer.

I created 4 files: index.html, main.mo, styles.css, and dfx.json on my computer.

They’re very simple files as I just want to try getting a single web page to work on ICP.

But, I’m stuck at this point on how to compile and upload it to my canister. Mainly because the tutorials I’ve found assume you don’t have a developer account or canister already and start right from scratch. And I can’t seem to continue from my point using these tutorials.

One thing I need to understand (among other things):

Is the developer account linked to a specific canister? So, do I need to create re-create my developer account so it’s connected to the canister I created using the NNS?

Anyways, these are the steps I tried so far:

I tried dfx build and I got the message:

Error: Cannot find canister id. Please issue ‘dfx canister create [name]’.

So, I issued the command: dfx canister create [name].

And then I got an error again:

Error: An error happened during communication with the replica: error sending request for url (http://127.0.0.1:nnnn/api/v2/status): error trying to connect: tcp connect error: Connection refused (os error 111)

I’m using dfx version 0.16.0.

Please note, I do know some html, css, and php from manging websites on WordPress, but, otherwise, I’m not a programmer and don’t have a background in it.

Any help would be much appreciated.

Thanks in advance!

2 Likes

If you are running a local replica for development, make sure your environment is running with dfx start --background
If you are doing work on the main network, then make sure to add --network=ic to your commands, since it defaults to local

If you’re interested in writing canisters in TypeScript or JavaScript, Azle will soon (tomorrow or Thursday) have very easy support for uploading files on canister deploy, would work very well for a frontend.

Otherwise you’ll want to create an asset canister, just like a canister of type Motoko, you make one in your dfx.json of type asset I believe. You should be able to ask the little AI widget about it maybe?

Asset canister or soon Azle 0.20.0 will get you this functionality.

1 Like

I already have a canister I created using the nns.ic0.app website.

So, I used the command:
dfx canister start --network=ic [canister-id]

I had to enter my passphrase and then it responded:

Decryption complete.
Starting code for canister [canister_ID], with canister_id [canister_ID]
Error: Failed to start canister [canister_ID].
Caused by: Failed to start canister [canister_ID].
  Failed to call update function 'start_canister' regarding canister 'canister_ID'.
    Update call (without wallet) failed.
      The replica returned a replica error: reject code CanisterError, reject message Only controllers of canister canister_ID can call ic00 method start_canister, error code Some("IC0512")
Error explanation:
Each canister has a set of controllers. Only those controllers have access to the canister's management functions (like install_code or stop_canister).
The principal you are using to call a management function is not part of the controllers.
How to resolve the error:
To make the management function call succeed, you have to make sure the principal that calls the function is a controller.
To see the current controllers of a canister, use the 'dfx canister info (--network ic)' command.
To figure out which principal is calling the management function, look at the command you entered:
    If you used '--wallet <wallet id>', then the wallet's principal (the '<wallet id>') is calling the function.
    If you used '--no-wallet' or none of the flags, then your own principal is calling the function. You can see your own principal by running 'dfx identity get-principal'.
To add a principal to the list of controllers, one of the existing controllers has to add the new principal. The base command to do this is 'dfx canister update-settings --add-controller <controller principal to add> <canister id/name or --all> (--network ic)'.
If your wallet is a controller, but not your own principal, then you have to make your wallet perform the call by adding '--wallet <your wallet id>' to the command.

The most common way this error is solved is by running 'dfx canister update-settings --network ic --wallet "$(dfx identity get-wallet)" --all --add-controller "$(dfx identity get-principal)"'.

So, I fixed that by adding my principal id on my computer to the controller using the web interface on nns.ic0.app.

Then, I issued the command again:
dfx canister start --network=ic [canister-id]

I had to enter my passphrase. And it responded:

Decryption complete.
Starting code for canister [canister_ID, with canister_id [canister_ID]

Then, I issued the command:
dfx build

I had to enter my passphrase for my identity.
Response:

Decryption complete.
Error: Cannot find canister id. Please issue ‘dfx canister create [canister name]’

This is where I feel the main issue is. I already created a canister using the web on nns.ic0.app. I already funded it with 10T cycles.

So, I shouldn’t have to create a canister. I just want to work with that canister I already created and upload the files I have on my computer.

Anyways, instead of issuing that command, I issued:
dfx deploy --network=ic

I assume it’s going to deploy to the canister I explicitly named in the dfx start command at the beginning.

It asked for my passphrase for my identity. I entered it and it responded:

Deploying all canisters.
Creating canisters…
Creating canister [canister name]…
Error: Failed while trying to deploy canisters.
Caused by: Failed while trying to deploy canisters.
Failed while trying to register all canisters.
Failed to create canister ‘[canister name]’.
In order to create a canister on this network, you must use a wallet in order to allocate cycles to the new canister. To do this, remove the --no-wallet argument and try again. It is also possible to create a canister on this network using dfx ledger create-canister, but doing so will not associate the created canister with any of the canisters in your project.

This is my frustration as I don’t want to create a canister as I mentioned before. I just want to upload my compiled files to the existing canister to create a simple one page website.

I stopped here and I’ll update this when I get back to this.

If you create a canister using means other than dfx then dfx doesn’t know about that canister. You can link a canister name to a canister id like this

Thanks, I gave up on this and I’ll try it again.