Mainnet deployment
Overview
To make your canister available to others, you must deploy it to the mainnet.
If you are only deploying projects in a local development environment, see the local development scenario.
Prerequisites
Before you download and install this release of the IC SDK, verify the following:
You have an internet connection and access to a shell terminal on your local computer.
You have
Node.js
16.0.0
or newer installed if you want to access the default frontend for the default project.You have ICP tokens or cycles available for you to use.
You must have cycles available to complete this guide. To get cycles, you must either convert ICP tokens to cycles or be provided cycles from another source, for example, from a canister controlled by another developer or from a third-party cycles provider. This guide assumes that you have an account with ICP tokens available and illustrates how to convert ICP tokens into cycles.
For information about how to get ICP tokens, see how you can get ICP tokens.
For an introduction to using the Network Nervous System application to manage ICP tokens, see Network Nervous System dapp quickstart.
Check the connection to the mainnet
There is a reserved network alias that you can use to access the mainnet. The network alias is a system setting that’s defined internally, so there’s nothing you need to configure in your projects by default.
To check your connection to ICP:
Step 1: Check that you are in the root directory for your project, if needed.
Step 2: Check the current status of ICP and your ability to connect to it by running the following command for the network alias
ic
:
dfx ping ic
Step 3: Verify that the
dfx ping ic
command returns information about ICP.For example, you should see output similar to the following:
{
"ic_api_version": "0.18.0" "impl_hash": "d639545e0f38e075ad240fd4ec45d4eeeb11e1f67a52cdd449cd664d825e7fec" "impl_version": "8dc1a28b4fb9605558c03121811c9af9701a6142" "replica_health_status": "healthy" "root_key": [48, 129, 130, 48, 29, 6, 13, 43, 6, 1, 4, 1, 130, 220, 124, 5, 3, 1, 2, 1, 6, 12, 43, 6, 1, 4, 1, 130, 220, 124, 5, 3, 2, 1, 3, 97, 0, 129, 76, 14, 110, 199, 31, 171, 88, 59, 8, 189, 129, 55, 60, 37, 92, 60, 55, 27, 46, 132, 134, 60, 152, 164, 241, 224, 139, 116, 35, 93, 20, 251, 93, 156, 12, 213, 70, 217, 104, 95, 145, 58, 12, 11, 44, 197, 52, 21, 131, 191, 75, 67, 146, 228, 103, 219, 150, 214, 91, 155, 180, 203, 113, 113, 18, 248, 71, 46, 13, 90, 77, 20, 80, 95, 253, 116, 132, 176, 18, 145, 9, 28, 95, 135, 185, 136, 131, 70, 63, 152, 9, 26, 11, 170, 174]
}
Register, build, and deploy the application
After you have a cycles balance, you can register, build, and deploy your sample application.
To deploy your first application on the mainnet:
Step 1: In your terminal shell, check that you are still in the root directory for your project.
Step 2: Ensure that
node
modules are available in your project directory, if needed, by running the following command:
npm install
For more information about this step, see ensuring node is available in a project.
Step 3: Register, build, and deploy your first application by running the following command:
dfx deploy --network ic
The --network
option specifies the network alias or URL for deploying the dapp. This option is required to deploy your canister on the mainnet.
The dfx deploy
command output displays information about the operations it performs.
For example, this step registers two identifiers—one for the hello_backend
main program and one for the hello_frontend
frontend user interface—and installation information similar to the following:
Deploying all canisters.
Creating canisters...
Creating canister "hello_backend"...
"hello" canister created on network "ic" with canister id: "5o6tz-saaaa-aaaaa-qaacq-cai"
Creating canister "hello_frontend"...
"hello_assets" canister created on network "ic" with canister id: "5h5yf-eiaaa-aaaaa-qaada-cai"
Building canisters...
Building frontend...
Installing canisters...
Installing code for canister hello_backend, with canister_id 5o6tz-saaaa-aaaaa-qaacq-cai
Installing code for canister hello_frontend, with canister_id 5h5yf-eiaaa-aaaaa-qaada-cai
Authorizing our identity (default) to the asset canister...
Uploading assets to asset canister...
/index.html 1/1 (472 bytes)
/index.html (gzip) 1/1 (314 bytes)
/index.js 1/1 (260215 bytes)
/index.js (gzip) 1/1 (87776 bytes)
/main.css 1/1 (484 bytes)
/main.css (gzip) 1/1 (263 bytes)
/sample-asset.txt 1/1 (24 bytes)
/logo.png 1/1 (25397 bytes)
/index.js.map 1/1 (842511 bytes)
/index.js.map (gzip) 1/1 (228404 bytes)
/index.js.LICENSE.txt 1/1 (499 bytes)
/index.js.LICENSE.txt (gzip) 1/1 (285 bytes)
Deployed canisters.
If you didn’t convert enough ICP tokens to cycles to complete the operation, you can add cycles to your balance by running a command similar to the following:
dfx cycles convert 1.005 --network ic
This command converts an additional 1.005
ICP tokens to cycles. The command returns output similar to the following:
Transfer sent at BlockHeight: 81520
Canister was topped up!
Step 4: Call the
hello_backend
canister and the predefinedgreet
function by running the following command:
dfx canister --network ic call hello_backend greet '("everyone": text)'
Let’s take a closer look at this example:
Using the
--network ic
option indicates that the canister you want to call is deployed on theic
. Theic
network alias is an internally-reserved alias for accessing the Internet Computer blockchain mainnet.Note that the
--network ic
option must precede the operation subcommand, which, in this case, is thedfx canister call
command.The
hello_backend
argument specifies the name of the canister you want to call.The
greet
argument specifies the name of the function you want to call in thehello
canister.The text string
everyone
is the argument that you want to pass to thegreet
function.Step 5: Verify the command displays the return value of the
greet
function. For example:
("Hello, everyone!")
Step 6: Rerun the
dfx cycles balance --network ic
command or refresh the browser to see your new cycle balance and recent activity.
Test the dapp frontend
Now that you have verified that your dapp has been deployed and tested its operation using the command line, let’s verify that you can access the frontend using your web browser.
To access the dapp frontend:
Step 1: Open a browser.
Step 2: Navigate to the frontend for the dapp using a URL that consists of the
hello_frontend
identifier and theboundary.icp0.io
suffix.
If you didn’t make a note of the canister identifier, you can look it up by running the following command:
dfx canister --network ic id hello_assets
For example, the full URL should look similar to the following:
https://gsueu-yaaaa-aaaae-aaagq-cai.icp0.io
Navigating to this URL displays the HTML entry page for the template application. For example:
Step 3: Type a greeting, then click Click Me to return the greeting.
Next steps
Want to go further? Start the developer ladder series.