Skip to main content

Hello, world!

View this sample's code on GitHub

This example demonstrates a canister called hello_world, which exports a method called main, which prints Hello World! to the console.

Prerequisites

Verify the following before running this demo:

  • You have downloaded and installed dfx.

  • You have stopped any process that would create a port conflict on 8000.

  • Clone the example dapp project: git clone https://github.com/dfinity/examples

Security considerations and security best practices

If you base your application on this example, we recommend you familiarize yourself with and adhere to the security best practices for developing on ICP. This example may not implement all the best practices.

Demo

  1. Start a local internet computer.

    dfx start
  2. Open a new terminal window.

  3. Reserve an identifier for your canister.

    dfx canister create hello_world
  4. Build your canister.

    cd examples/motoko/hello-world
    dfx build
  5. Deploy your canister.

    dfx canister install hello_world
  6. Invoke the main method.

    dfx canister call hello_world main
  7. Observe the following output in the terminal where your local Internet Computer is running.

    debug.print: Hello World!

Issues

Don't see any output? Be sure to check the terminal where your local replica is running and not the terminal from which you invoked the main method.