View this sample's code on GitHub
Who am I? demonstrates how entities on the Internet Computer are identified. Every entity, such as a user or canister smart contract, has a principal identifier. Principals can be used for identification and authentication. Who am I? uses Internet Identity (II) for user authentication, then displays the principal identifier associated with that Internet Identity on the user interface.
Clone the example project:
git clone https://github.com/dfinity/examples
cd examples/motoko/who_am_iStart the local network and deploy:
icp network start -d
icp deployThe frontend is served by the asset canister. To run the Vite dev server with hot reload during frontend development:
npm run devWhen done, stop the local network to free the port and clear state:
icp network stopWhen you're ready for mainnet, install icp-cli locally and follow the mainnet deployment guide. Mainnet requires ICP tokens and cycles — managing identities securely is much better from your own machine.
The src/backend/backend.did file defines the backend canister's public interface. The frontend TypeScript bindings are auto-generated from this file during the frontend build.
If you modify the backend's public API, regenerate the .did file using the Motoko compiler:
$(mops toolchain bin moc) --idl -o src/backend/backend.did src/backend/main.moIf you base your application on this example, it is recommended that you familiarize yourself with and adhere to the security best practices for developing on ICP. This example may not implement all the best practices.