Deploying a Canister to the IC Mainnet Using Cycles Token (XTC)

This guide will go through the process of funding a canister’s deployment to the Internet Computer’s mainnet using Dank’s Cycles Token! This guide was built using DFX 0.8.0.

Dank
Dank
7 min readAug 30, 2021

--

If you’re learning how to deploy a canister to the Internet Computer mainnet, this guide is a great place to start. Similar to ‘gas’ on Ethereum, ‘cycles’ are used to pay for computational power used by canisters living on the Internet Computer mainnet. Deployment of a canister to mainnet takes computational power, and therefore, costs cycles.

In this tutorial, we will teach you to use your Principal ID’s Cycles Token (XTC) balance to fund the deployment of a canister through DFX, the command-line tool built by DFINITY to interact with the Internet Computer.

You can do this directly using the Principal ID of one of your existing DFX Identities, or by importing your Plug Principal ID into DFX.

Feeling a bit lost on what Cycles Tokens (XTC) are, and why you’d use them to develop instead of a cycles wallet? You can catch up here, and come back for the guide later 😉

0. Installing DFX 🛠

Before we do anything, we need DFX, a tool in DFINITY’s Software Development Kit, to interact with the IC through the command line. If you don’t have DFX installed, go ahead and open a terminal shell and run this command to download the latest version:

Note: We are using DFX V0.8.0 for this tutorial. DFX is subject to change, if you have any issues throughout this tutorial, check your version using:

That was easy! DFX is a very powerful tool that we will be using throughout this entire tutorial. In this next section, we’ll learn to use your Principal ID, in conjunction with DFX, to acquire a balance of Cycles Token (XTC).

1. Obtaining some XTC 🚰

At the time of writing, DFINITY has set up a Cycles Faucet that gives a one-time 100$ cycles redeem (or XTC redeem!) to any eligible developers’ wallets of choice so that they can begin working on applications for the Internet Computer. Navigate to the Cycles Faucet and redeem if you haven’t already.

You have two options here:

A) Redeem Using a Principal ID generated by DFX:

Using a Principal ID that was generated by DFX is as simple as it gets.

Get your DFX identity’s Principal ID by opening the command line and running:

Copy the string of characters that was returned to you. This is your Principal ID, your unique and universal identifier on the IC. Go ahead and paste your Principal ID into the Cycles Faucet as instructed, and choose Dank’s XTC option as your deposit method. Done!

B) Redeem Using a Principal ID generated by Plug

Using a Principal ID generated from your wallet in Plug involves a couple of extra steps.

Open your wallet in Plug, hover over your account name located at the top center portion of the app, and click to copy your Principal ID.

Paste your Principal ID into the Cycles Faucet as instructed, and then choose Dank’s XTC option as your deposit method.

Congrats! Your Principal ID now holds a balance of XTC on the XTC canister’s ledger.

Bonus Round: Exporting your Plug Identity to DFX 🚢

However, because this Principal ID was generated through Plug, it does not live on DFX as an identity… yet.

To import a Principal ID to DFX, we need a .pem file. This file allows DFX to work some magic behind the scenes to securely import the keys associated with your Principal ID. Lucky for us, Plug has built a feature that creates a download for the .pem file associated with your wallet’s Principal ID.

Inside Plug, go to Settings > Export DFX Identity and follow the instructions to download your .pem file. Keep this file safe and do not share it with others or they will be able to make calls using your Principal ID.

Back inside a terminal shell, import your Plug account’s Principal ID with this command:

Lastly, switch over to your newly created DFX identity using:

2. Deploying your Canister using XTC

With your Principal ID and your XTC balance ready, you have all the necessary tools to have your first canister deployed to the Internet Computer mainnet.

First, navigate to the directory on your local machine where you want to create your project. Use the following command in terminal to create a new dfx project:

A ‘Hello World’ application is loaded by default. The application comes with a backend canister written in Motoko, the IC’s native programming language, and a frontend canister written in HTML, CSS, and JavaScript.

If you’ve built canisters already and would like to add any of your own for deployment, add them to the src folder and update the dfx.json file accordingly.

By default, DFX projects use webpack to provide the framework for the front-end. As a result, you need node.js installed in your project’s root directory to be able to compile to the front end. To do this, navigate to the root directory of the DFX project you just created and run the following:

Set the XTC Canister as your DFX Wallet 💼

Now for the fun part, we are ready to start interacting with the XTC canister. First, we need to set the XTC canister as the personal cycles wallet of the identity being used on DFX.

This will allow us to make calls to the XTC canister against our Principal ID’s balance to do things like, I don’t know, fund the deployment of a canister using XTC 😉 To do this, input the command:

This might look like gibberish, but ‘aanaa-xaaaa-aaaah-aaeiq-cai’ is the Cycles Token (XTC) Canister ID, the ID that we are setting cycles wallet to.

Want to confirm you’re on the right track? We can make a call to check what our wallet is now set to on the Internet Computer mainnet.

Recognize this address? It should be aanaa-xaaaa-aaaah-aaeiq-cai, the XTC canister ID. Pretty cool right?

NOTICE: The next step involves reserving slots and using computational power on the Internet Computer mainnet. The cost to perform these actions are just over 4 Trillion Cycles per canister. XTC is backed 1:1 with cycles, so you will need just over 4 XTC per canister you’d like to have deployed.

Deploying your canisters to mainnet 📟

Our canister’s are currently only deployed to our local machine, let’s change that. The first step is to reserve a slot on the Internet Computer mainnet for our canisters. Reserve these slots for all of your canisters by running:

If you don’t want to reserve slots for all your canisters, you can specify a canister by replacing the -all flag with the specific canister’s name as such:

Your canister is now on mainnet, but it is still an empty canister. You need to push/install the code you’ve developed locally to that new canister on mainnet! This can be done using:

And just like that, your canister is now live & installed on mainnet 🚀 Don’t just take our word for it, now that your canister lives on the IC mainnet, we can fetch it in a browser.

Your browser serves the frontend of your application via a URL that uses the frontend canister ID. Don’t worry if you didn’t write this down, we can request it using DFX.

Note: ‘<project-name>_assets’ is the default name made for your applications frontend canister. If your project’s name is ‘Hello’, then your frontend canister has the name ‘Hello_assets’.

Copy the canister ID and head over to a browser window. Your canister lives at this URL:

If you haven’t made any changes to the default ‘Hello World’ project, the link you entered should retrieve a frontend that looks like this:

Happy Building! 👷‍♂️

You have successfully deployed a canister to the Internet Computer using Cycles Tokens (XTC)! The best part? If you’ve used the Cycles Faucet, you still have around… 75 – (4 *deployments) Cycles Token (XTC) left to build some other awesome stuff on the IC!

Hop into our Discord, or mention us on Twitter to share what you’ve been building. Our team is always happy to help!

--

--

Dank
Dank

Open Internet Service on DFINITY’s Internet Computer.