Motoko examples
Core Motoko
These examples show the Motoko language as a backend language for the IC, operating directly with clients, without a front end component.
Basic
actor_reference
-- IC management canister as an actor (reference).counter
-- basic (stable) variable demo.echo
-- basic query function demo.factorial
-- basic factorial demo.hello-world
-- basic hello world demo.hello_cycles
-- basic cycles demo.persistent-storage
-- basic stable var demo.whoami
-- basic caller identification demo.
Intermediate
classes
-- dynamic actor (class) instantiation.pub-sub
-- multiple canisters, with publisher-subscriber inter-canister calls.quicksort
-- sorting an array, via Quick Sort, in Motoko.simple-to-do
-- CRUD-like demo service, sans a front end; see also:phone-book
andsuperheroes
.calc
-- more advanced version ofcounter
demo.icrc2-swap
-- deposit, swap, and withdraw two ICRC-2 tokens.
Minimal front end.
These examples use a minimal front end component.
random_maze
-- random maze generation, with IC-based randomness.cert_var
-- simple certified variable (a single 32-bit number), with client-side certificate validation.minimal-counter-dapp
-- counter dapp with minimal front end.
Full stack.
These examples use a "conventional" front end component (via React.Component
).
life
-- demonstrates upgrades among three versions and stable state migration.phone-book
-- CRUD-like demo service.superheroes
-- CRUD-like demo service.
Security Considerations and Security Best Practices
If you base your application on one of these examples, we recommend you familiarize yourself with and adhere to the Security Best Practices for developing on the Internet Computer. The examples provided here may not implement all the best practices.