Skip to main content

# Tutorial 1 - Deploy sample code

This is a quick tutorial to deploy a "Hello World" dapp to the Internet Computer (IC) in 10 minutes or less. Deployment of the dapp only requires basic knowledge of using a terminal.

Before starting, take a look at a version of this dapp running on-chain: https://6lqbm-ryaaa-aaaai-qibsa-cai.icp0.io/

In this tutorial, you will learn how to:

1. Install the Canister SDK
2. Build and deploy a dapp locally
3. Collect free cycles to power your dapp
4. Create a "cycles wallet" from which you can transfer cycles to any other dapps you want to power
5. Deploy a dapp on-chain

This simple Hello dapp is composed of two canister smart contracts (one for backend and one for frontend). The dapp accepts a text argument as input and returns a greeting. For example, if you call the greet method with the text argument Everyone on the command-line via the canister SDK (see instructions below on how to install the canister SDK), the dapp will return Hello, Everyone! either in your terminal:

$dfx canister call hello_backend greet Everyone$ "Hello, Everyone"

Or via the dapp in a browser, a pop-up window will appear with the message: Hello, Everyone!

Note that the "Hello World" dapp consists of backend code written in Motoko, a programming language specifically designed for interacting with the IC, and a simple webpack-based frontend.

This tutorial requires Linux, macOS 12.* Monterey or later, or Windows with a Windows Subsystem for Linux (WSL) installation.

## Topics Covered in this Tutorial​

• Canisters are the smart contracts installed on the IC. They contain the code to be run and a state, which is produced as a result of running the code. As is the case of the "Hello World" dapp, it is common for dapps to be composed of multiple canisters.

• Cycles refer to a unit of measurement for resource consumption, typically for processing, memory, storage, and network bandwidth consumed on the IC. For the sake of this tutorial, cycles are analogous to Ethereum’s gas: cycles are needed to run dapps, but unlike gas they are stable and less expensive. Every canister has a cycles account from which the resources consumed by the canister are charged. The IC’s utility token (ICP) can be converted to cycles and transferred to a canister. ICP can always be converted to cycles using the current price of ICP measured in SDR (a basket of currencies) using the convention that one trillion cycles correspond to one SDR. Get free cycles from the cycles faucet.

• A cycles wallet is a canister that holds cycles and powers up dapps.

## 1. Installing Tools​

To build and deploy the Hello dapp, you need to install the following tools.

### dfx​

In this tutorial, we use a Canister SDK called dfx, which is the default SDK maintained by the DFINITY foundation.

To install dfx, run:

### Option 1: Acquiring cycles via the free cycles faucet (2 min)​

This option is best for people who want minimal time investment and have never used cycles faucet (faucet can be used only once).

For the purposes of this tutorial, you can acquire free cycles for your Hello dapp from the cycles faucet. Follow the instructions here: Claim your free cycles.

#### Check your cycles balance​

Now that you have used the cycles faucet, in terminal B you can check your cycles balance:

dfx wallet --network ic balance

You should see around 20 trillion cycles if you run this after using the cycles wallet. If so, skip to section 5. Deploying on-chain.

If you do not see any cycles, deploying on-chain in the rest of the tutorial will not work. You should try Option 2: Converting ICP token into cycles.

### Option 2: Converting ICP tokens into cycles (5 min)​

This option is best for people who have already exhausted the cycles wallet or who want to set up their environment to add more cycles in the future.

To convert ICP tokens into cycles, you first need to obtain some ICP and transfer to the right account. You can get ICP tokens on exchanges, or ask someone you know to send you some. To figure out which account to transfer the ICP tokens to, run the following:

dfx ledger account-id

This will display your account number on the ICP ledger. It looks similar to this:

e213184a548871a47fb526f3cba24e2ee2fbbc8129c4ab497ef2ce535130a0a4

## Wrap-up​

Congratulations! You have built a dapp fully on-chain (both backend and frontend) within 10 minutes.

Tutorial takeaways:

• Dapps can be composed of multiple canisters
• Dapps can be deployed locally and on-chain
• Cycles are needed power dapps
• Get free cycles from the cycles wallet
• Free cycles can be used to power additional dapps

### Starting from scratch​

If you wish to start from scratch, delete the SDK and associated profiles and re-install it. Follow the instructions here: Install, upgrade, or remove software.

Be sure to save any identities linked to dapps or ICP.

### Getting Stuck?​

If you get stuck or run into problems search for solutions or post questions in the Developer forum or DISCORD.

### Ready for the next challenge?​

Build DAOs, NFTs and more here.

### Want to learn more?​

If you are looking for more information before getting started or want to view a demonstration of how to deploy before you try it for yourself, check out the following related resources: