Quick start

This DFINITY Canister Software Development Kit (SDK) provides tools, sample code, and documentation to help you create programs to run on a locally-deployed Internet Computer network. This Quick Start assumes that you are installing the DFINITY Canister SDK for the first time.

To get started, let’s build and deploy a simple Hello application that has just one function—called greet. The greet function accepts one text argument and returns the result with a greeting similar to Hello, everyone! in a terminal if you run the application using the command-line or in an alert pop-up window if you access the application in a browser.

Before you begin

Before you download and install this release of the DFINITY Canister SDK, verify the following:

  • You have an internet connection and access to a shell terminal on your local macOS or Linux computer.

    Currently, the DFINITY Canister SDK only runs on computers with a macOS or Linux operating system.

  • You have node.js installed if you want to include the default template files for front-end development in your project.

If you aren’t sure how to open a new terminal shell on your local computer or how to install node.js, see Preliminary steps for newcomers. If you are comfortable meeting the prerequisites without instructions, continue to Download and install.

Download and install

You can download the latest version of the DFINITY Canister Software Development Kit (SDK) directly from within a terminal shell on your local computer.

To download and install:

  1. Open a terminal shell on your local computer.

    For example, open Applications, Utilities, then double-click Terminal or press +spacebar to open Search, then type terminal.

  2. Download and install the DFINITY Canister SDK package by running the following command:

    sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"

    This command prompts you to read and accept the license agreement before installing the DFINITY execution command-line interface (CLI) and its dependencies on your local computer.

  3. Type y and press Return to continue with the installation.

    The command displays information about the components being installed on the local computer.

Verify the SDK is ready to use

If the installation script runs without any errors, everything you need to start developing programs that run on the Internet Computer platform will be available on your local computer.

To verify the SDK is ready to use:

  1. Open a terminal shell on your local computer, if you don’t already have one open.

  2. Check that you have the DFINITY execution command-line interface (CLI) installed and the dfx executable is available in your PATH by running the following command:

    dfx --version

    The command displays version information for the dfx command-line executable similar to the following:

    dfx 0.6.12
  3. Preview usage information for the other dfx command-line sub-commands by running the following command:

    dfx --help

    The command displays usage information for the dfx parent command and its subcommands.

Install the language editor plug-in

If you are planning to write a program using Motoko and use Visual Studio Code (VSCode) as your editor, you can install the Motoko language client plug-in for VSCode. The Motoko plug-in provides syntax highlighting, type information, and auto-completion features.

To install the plug-in:

  1. Download and install Visual Studio Code, if it not already installed on your local computer.

  2. Click View, then select Extensions.

  3. Type motoko in the Search field.

  4. Select the Motoko language support published by DFINITY Foundation, then click Install.

If your program has dependencies, you might also want to install the Vessel package manager for Motoko. For instructions, see the ReadMe. To download the latest release, go to the vessel GitHub repository.

Create a new project

Applications for the Internet Computer start as projects. You create projects using the dfx parent command and its subcommands. Creating a new project with dfx adds a default project directory structure to your development workspace with template files to get you started.

To create a new project for your first application:

  1. Open a terminal shell on your local computer, if you don’t already have one open.

  2. Create a new project named hello by running the following command:

    dfx new hello

    The dfx new hello command creates a new hello project directory, template files, and a new hello Git repository for your project.

    If you use a different project name instead of hello, make note of the name you used. You’ll need to use that project name in place of the hello project name throughout these instructions.

  3. Change to your project directory by running the following command:

    cd hello

Start the local network

Before you can build your first project, you need to connect to the Internet Computer network either running locally in your development environment or running remotely on a sub-network that you can access.

These instructions assume you are running the Internet Computer locally. If you are connecting to an external Internet Computer network, you can skip this section.

As a best practice, this step requires you to have two terminal shells open, so that you can start and see network operations in one terminal and manage your project in another.

To start the network locally:

  1. Open a new second terminal window or tab on your local computer and navigate to your project directory.

    For example, you can do either of the following if running Terminal on macOS:

    • Click Shell, then select New Tab to open a new terminal in your current working directory.

    • Click Shell and select New Window, then run cd ~/ic-projects/hello in the new terminal if your hello project is in the ic-projects working folder.

    You should now have two terminals open with your project directory as your current working directory.

  2. Start the Internet Computer network on your local computer in your second terminal by running the following command:

    dfx start

    Depending on your platform and local security settings, you might see a warning displayed. If you are prompted to allow or deny incoming network connections, click Allow.

  3. Leave the terminal window that displays network operations open and switch your focus to the first terminal window where you created your new project.

    You perform the remaining steps in the terminal that doesn’t display network operations.

Register, build, and deploy the application

After you connect to the Internet Computer network running locally in your development environment, you can register, build, and deploy your application locally.

If you are connecting to an external Internet Computer network, you will need to use the --network option to deploy to that network. For information about deploying on the Internet Computer running remotely, see Deploying on the Internet Computer.

To deploy your first application locally:

  1. Check that you are still in the root directory for your project, if needed.

  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.

  3. Register, build, and deploy your first application by running the following command:

    dfx deploy

    If you have access to the Internet Computer running remotely, you can deploy to the that network instead of deploying locally by specifying the --network option and the network alias configured in the dfx.json file. For information about deploying on the Internet Computer running remotely, see Deploying on the Internet Computer.

    The dfx deploy command output displays information about the operations it performs. For example, this step registers two network-specific identifiers—one for the hello main program and one for the hello_assets front-end user interface—and installation information similar to the following:

    Installing code for canister hello, with canister_id 75hes-oqbaa-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa-q
    Installing code for canister hello_assets, with canister_id cxeji-wacaa-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa-q

    If you created a project with a different name, however, your canister names will match your project name instead of hello and hello_assets.

  4. Call the hello canister and the predefined greet function by running the following command:

    dfx canister call hello greet everyone

    This example uses the dfx canister call command to pass "everyone" as an argument to the greet function.

    Remember, however, that if you created a project with a different name, the canister name will match your project name and you’ll need to modify the command line to match the name you used instead of hello.

  5. Verify the command displays the return value of the greet function.

    For example:

    ("Hello, everyone!")

Test the application front-end

Now that you have verified that your application has been deployed and tested its operation using the command line, let’s verify that you can access the front-end pop-up window using your web browser.

  1. Open a browser.

  2. Navigate to the default address and port number 127.0.0.1:8000, then append /?canisterId= and the hello_assets identifier to the URL.

    For example, the full URL should look similar to the following:

    http://127.0.0.1:8000/?canisterId=cxeji-wacaa-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa-q

    Navigating to this URL displays the prompt pop-up window. For example:

    Prompt pop-up window

  3. Type a greeting, then click OK to return the greeting.

    For example:

    Hello

  4. Click OK to close the alert pop-up window.

Stop the local network

After testing the application in the browser, you can stop the local Internet Computer network so that it doesn’t continue running in the background.

To stop the local network:

  1. In the terminal that displays network operations, press Control-C to interrupt the local network process.

  2. Stop the local Internet Computer network running on your local computer by running the following command:

    dfx stop

Next steps

This Quick Start touched on only a few key steps to introduce the basic workflow you follow to develop programs of your own. There are more detailed examples and tutorials for you to explore in the Tutorials section of the SDK Developer Tools and in the Motoko Programming Language Guide.