Internet Computer Basics — Part 3: Funding a Cycles Wallet

A guide for using the command line and the NNS frontend dapp to obtain cycles for running canisters and dapps.

Mikhail Turilin
The Internet Computer Review
6 min readJun 29, 2022

--

The Internet Computer requires developers to feed running canisters with “cycles,” which are stored in cycles wallets. In the previous article, we discussed how to create a cycles wallet and claim free cycles from the DFINITY Cycles Faucet. This article will explain how to obtain more cycles by purchasing them using either the command line or the Network Nervous System (NNS) frontend dapp.

How to buy ICP utility tokens on an exchange

You will first need to acquire some ICP utility tokens from an exchange such as Coinbase or Binance. Here’s an example of how you can purchase ICP tokens on Coinbase:

  1. Sign in to the Coinbase app
  2. Go to the “Trade” tab
  3. Select “Internet Computer” coin
  4. Complete the purchase

The process should be similar for other coin exchanges, like Binance, Kraken, or Gemini.

How to send ICP tokens from an exchange to your developer account

Since Internet Computer tools like the NNS frontend dapp only work with accounts they directly control, you will need to send ICP tokens from your exchange account to your developer account.

First, you will need to know your ledger account ID, which is where you will be sending your ICP tokens.

If you plan to use dfx to purchase cycles (you can read more about this below), you can type the following command. Just be sure to backup your identity file before sending funds to it.

%  dfx ledger account-id
5c40ac64d8f8d12f4c1355ec0b1cf54725322f4ecf2162fbda1937c3c0cf4886

To get your ledger account ID from the NNS dapp, log in using your Internet Identity credentials at https://nns.ic0.app. You will see the list of your accounts with balances:

You can get your account ID from the NNS “Accounts” page

Once you have collected your account ID, you are ready to send the tokens. In the Coinbase app, you can follow the process below:

  1. Go to the “Pay” screen.
  2. Press “Send.”
  3. Choose ICP tokens.
  4. Enter the ledger account ID we received from the command line.
  5. Preview the order and press “Send.”
Sending tokens from Coinbase to your developer account

Within a few seconds, you will see that the balance of your account has changed. Here’s an example of how you can check your balance for your dfx identity:

%  dfx ledger --network ic balance
0.74960000 ICP

How to create a new wallet from the command line

Now you can create a new empty canister for your wallet:

%  dfx ledger --network ic create-canister $(dfx identity get-principal)
--
amount 0.25
Transfer sent at BlockHeight: 3342057
Canister created with id: "ttk2q-5yaaa-aaaap-qadba-cai"

After creating the canister, you need to deploy the wallet into this canister. Here ttk2q-5yaaa-aaaap-qadba-cai is the ID of the canister you received in the previous step.

%  dfx identity --network=ic deploy-wallet ttk2q-5yaaa-aaaap-qadba-cai
Creating a wallet canister on the ic network.
The wallet canister on the "ic" network for user "old_identity" is "ttk2q-5yaaa-aaaap-qadba-cai"

Now you can check the balance of the new wallet:

% dfx wallet --network=ic balance
4.211 TC (trillion cycles).

The current wallet setting is stored in your file system in the folder ~/.config/dfx/identity/<identity_name>/wallets.json. For example, on my computer, this file looks like this:

{
"identities": {
"old_identity": {
"ic": "ttk2q-5yaaa-aaaap-qadba-cai"
}
}
}

How to add cycles to an existing wallet

Let’s say you have a wallet, but it doesn’t have enough cycles to deploy canisters. How do you add more cycles?

The process follows these steps:

  1. Send ICP tokens to a ledger account ID that you control.
  2. Convert ICP tokens to cycles and deposit them on your cycles wallet canister.

These operations can be done using the command line or the NNS frontend dapp.

Adding cycles to a wallet using the command line

First, make sure you have enough funds on your ledger account ID:

% dfx ledger --network=ic balance
1.42550150 ICP

In this example, I have ~1.43 ICP on my account. If you don’t have enough funds, please see the section “How to buy ICP utility tokens on an exchange?”

Then you need to get the wallet address:

% dfx identity --network=ic get-wallet
ttk2q-5yaaa-aaaap-qadba-cai

In this example, my wallet address is ttk2q-5yaaa-aaaap-qadba-cai.

You can top up your wallet using the dfx ledger top-up command:

% dfx ledger --network=ic top-up --amount 0.5 ttk2q-5yaaa-aaaap-qadba-cai
Transfer sent at BlockHeight: 3350701
Canister was topped up!

You can confirm that your cycle balance has increased:

% dfx wallet --network=ic balance
4.211 TC (trillion cycles).

Also, you can double-check that your account balance is decreased by ~0.5 ICP:

% dfx ledger --network ic balance
0.92530150 ICP

Adding cycles to a wallet using the NNS frontend app

If you prefer a graphical UI, you can add cycles to a wallet using the NNS frontend app.

You will need the address of your wallet canister that you can get using this command:

% dfx identity --network=ic get-wallet
ttk2q-5yaaa-aaaap-qadba-cai

In this example, my wallet address is ttk2q-5yaaa-aaaap-qadba-cai.

Then log in to the NNS dapp using your Internet Identity credentials at https://nns.ic0.app. You will see the list of your accounts with balances:

You can your account balance from the NNS “Accounts” page

Go to the “Canisters” tab and click “Create or Link Canister”:

NNS “Canisters” tab

Press “Link Canister to Account”:

NNS “Add Canister” screen

Enter the wallet ID that you received from the terminal earlier and click “Attach Canister”:

NNS “Attach Canister” screen

You will see the canister status screen with the canister ID. Since you haven’t added your NNS identity as the canister controller, you will see the status message, “You are not the controller of this canister.” This is OK. You can still add cycles to this canister. To do so, press the “Add Cycles” button:

NNS “Canister Details” screen

Choose the account that you will use to buy cycles:

NNS “Top Up Canister” screen

Enter the amount of ICP you would like to convert into cycles. You will see a preview of how many cycles will be deposited. Then press “Review Cycles Purchase”:

NNS cycles purchasing screen

Press “Confirm and Send” to finalize your purchase:

NNS “Review Cycles Purchase” screen

Now the transaction is completed!

NNS cycles purchase confirmation screen

You can check your wallet balance using the command line:

% dfx wallet --network=ic balance
19001371501346 cycles.

Summary

This article demonstrated how you can:

  • Acquire some ICP tokens from an exchange.
  • Create new wallets from a command line and fund them from your ICP account.
  • Add cycles to your wallets from a command line or GUI using the NNS frontend dapp.

Now you are ready to deploy some canisters to production! I will cover canister deployment in the next installment of Internet Computer Basics.

____

Start building at internetcomputer.org and join the developer community at forum.dfinity.org.

--

--