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
Start a local internet computer.
dfx start
Open a new terminal window.
Reserve an identifier for your canister.
dfx canister create hello_world
Build your canister.
cd examples/motoko/hello-world
dfx buildDeploy your canister.
dfx canister install hello_world
Invoke the
main
method.dfx canister call hello_world main
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.