Skip to main content

Who am I?

This example demonstrates how a canister can identify its caller and itself.

Prerequisites

This example requires an installation of:

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

Begin by opening a terminal window.

Step 1: Setup the project environment

Navigate into the folder containing the project's files and start a local instance of the Internet Computer with the commands:

cd examples/motoko/whoami
dfx start --background

Step 2: Build and deploy the canister

dfx canister install whoami --argument='(principal "2mxjj-pyyts-rk2hl-2xyka-avylz-dfama-pqui5-pwrhx-wtq2x-xl5lj-qqe")'
dfx build
dfx deploy

Step 3: Invoke the whoami method

dfx canister call whoami whoami

Step 4: Observe your principal identifier

Step 5: Invoke the id method

dfx canister call whoami id

Step 6: Observe the principal identifier of your canister

Security considerations and 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 the Internet Computer. This example may not implement all the best practices.

For example, the following aspects are particularly relevant for this app: