1.5 Deploying to the mainnet
If you did not obtain cycles in the previous tutorial, 1.4 Acquiring and using cycles, then you can skip this module and continue with the rest of the tutorial series.
Now that you have cycles to pay for your canister's resources, you can deploy a dapp on the mainnet. When a canister is deployed to the mainnet, its code will be hosted on one of the mainnet's subnets and replicated across every node within that subnet. The canister will be hosted on the mainnet until it is manually uninstalled by the developer or until it runs out of cycles and is uninstalled automatically.
Once a dapp is deployed on the mainnet, it can be accessed from the canister's public URL and can communicate with other canisters that are deployed on the mainnet.
- Prerequisites
If you did not obtain cycles in the previous tutorial, 1.4 Acquiring and using cycles, then you can skip this module and continue with the rest of the tutorial series.
To deploy your dapp to the mainnet, first assure that your terminal window is open and you've navigated into the directory of a project, such as the simple "Hello, world!" dapp that you created in module 0.6 Introduction to dfx or a project downloaded from ICP Ninja.
This tutorial will use the "Hello, world!" dapp from module 0.6 Introduction to dfx.
Now it's time to register, build, and deploy your dapp. First, let's check to make sure you have an active connection to the mainnet. Run the command:
dfx ping ic
A successful connection to the mainnet will return an output such as:
{
"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]
}
Now, you can deploy your dapp to the mainnet by running the following command:
dfx deploy --network ic
In this command, the --network
flag specifies which network the dapp should be deployed on. Other options for this flag are --network local
and --network playground
. This tutorial series covered these in module 1.1: exploring a live demo.
Using the flag --network ic
is required to deploy your dapp on the mainnet. If this flag is not included, your dapp will only be deployed locally by default.
This command doesn't include a canister name, meaning it will automatically deploy all canisters that are specified in the dfx.json
file. You can specify a single canister to be deployed by including the canister's name in the command, such as:
dfx deploy hello_world_backend --network ic
The output of this command will include information about what actions are happening. For example, the output should resemble the following:
Deploying all canisters.
hello_world_backend canister created on network ic with canister id: 7irr6-ryaaa-aaaak-apbrq-cai
hello_world_frontend canister created on network ic with canister id: 75wat-qqaaa-aaaak-apbsa-cai
Installed code for canister hello_world_backend, with canister ID 7irr6-ryaaa-aaaak-apbrq-cai
Installed code for canister hello_world_frontend, with canister ID 75wat-qqaaa-aaaak-apbsa-cai
Deployed canisters.
URLs:
Frontend canister via browser:
hello_world_frontend: https://75wat-qqaaa-aaaak-apbsa-cai.icp0.io/
Backend canister via Candid interface:
hello_world_backend: https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=7irr6-ryaaa-aaaak-apbrq-cai
If your cycles balance doesn't contain enough cycles to complete this deployment, you can convert more ICP into cycles with the command:
dfx cycles convert 1.005 --network ic
Now, let's use your dapp! To access the dapp's frontend, open the "Frontend canister via browser" URL returned in the deployment output:
Frontend canister via browser:
hello_world_frontend: https://75wat-qqaaa-aaaak-apbsa-cai.icp0.io/
When you open this URL in your web browser, you will see the app's frontend user interface. Your dapp is hosted 100% onchain, does not rely on your local replica to keep running, and you can send this URL to your friends and get them to use your app!
To avoid burning through your cycles, once you are finished with this tutorial, consider stopping your project's canisters with the dfx canister stop
command.

Did you get stuck somewhere in this tutorial, or do you feel like you need additional help understanding some of the concepts? The ICP community has several resources available for developers, like working groups and bootcamps, along with our Discord community, forum, and events such as hackathons. Here are a few to check out:
- Developer Discord
- Developer Liftoff forum discussion
- Developer tooling working group
- Motoko Bootcamp - The DAO Adventure
- Motoko Bootcamp - Discord community
- Motoko developer working group
- Upcoming events and conferences
- Upcoming hackathons
- Weekly developer office hours to ask questions, get clarification, and chat with other developers live via voice chat.
- Submit your feedback to the ICP Developer feedback board