Developer Resources

Example Code

Discover quick code references that showcase code examples for Motoko, Rust, and C++

IC Academy » Developer Resources » Example Code

Code References

Curated set of code examples

For more examples, have a look at the following resources: Examples Repo, Awesome Dfinity, and Hackathon Projects

Motoko and Rust Examples

The following example is available in both Motoko and Rust.

  • Hello: The hello example is the decentralized equivalent of hello world. The webpage is served by a separate frontend and backend canister

Motoko Examples

The Motoko Playground features a range of examples, some of which are featured in the following. You can test Motoko examples in the simple environment of the playground without having to use the Dfinity SDK. However, the playground does not support decentralized applications with frontends.

Basic examples – getting started

Illustrations of the basic concepts of the Motoko programming language and the Internet Computer.

Actor references

IC management canister used as an actor (reference)

actor_reference
Counter Example

Demo of a counter application (basic variable demo)

counter 
Echo Effect

Demo of a simple echo effect (basic query function)

echo
Factorial Demo

Function calculating integers (basic factorial demo)

factorial
Hello World Demo

Canister printing Hello World! (basic demo)

hello-world 
Hello Cycles

Receive/transfer cycles, check cycle balance

hello_cycles
Who Am I? Demo

Demo of a canister identifying its caller and itself

whoami 
Intermediate examples – use cases of basic concepts

The next set of examples illustrate how you can use simple concepts of Motoko in common use cases. Included are examples of how you can use Motoko to build basic backend functionalities.

Actor Classes

Simple use of actor classes (dynamic actor instantiation)

classes 
Pub/Sub Design Pattern

Canisters with publisher-subscriber inter-canister calls

pub-sub
Quicksort

Quicksort algorithm (sorting array via Quick Sort)

quicksort
Simple To-Do

Creating a simple to-do checklist application

simple-to-do 
Four-Function Calculator

Advanced version of the counter demo

calc 
Ledger Transfer 

dApp that transfers ICPs to active users

ledger transfer
Simple frontends – in JavaScript

The previous examples did not include frontends. The following two examples show you how you can create minimal frontends and backends in JavaScript.

Random Maze Generator

Random maze via IC-based randomness

random_maze
Certified Variable

Using a single cryptographically certified variable

cert_var

Rust Examples

The next set of examples are written in Rust.

Beginner examples – in Rust

Two examples highlighting how you can use Rust:

Pub/Sub Design Pattern

Demo similar to the Motoko pub-sub example

Pub Sub
Tokens Transfer

Canister that can transfer tokens to other accounts

Tokens Transfer 

C

Demo projects written in the programming language C. More examples can be found here: C++ sample projects.

Please keep in mind that the following examples may need to be updated as they are likely to bit-rot

“Hello, world!”

Have a look at the dApp equivalent of the simple “Hello, world!” program

Hello Example

Community Projects

Curated list of community-built projects running on the Internet Computer

Awesome DFINITY