|
| 1 | +# Rust examples |
| 2 | + |
| 3 | +Canonical examples for building canisters on the Internet Computer with [Rust](https://docs.internetcomputer.org/languages/rust). Each example is self-contained: follow its README to deploy it locally with `icp-cli` and run its tests. Most examples have a Motoko counterpart in [`../motoko/`](../motoko/) implementing the same Candid interface. |
| 4 | + |
| 5 | +**New to ICP?** Start with [`hello_world`](hello_world/) — a full-stack canister with a frontend and the structural template for all examples. Then try [`who_am_i`](who_am_i/) for user authentication with [Internet Identity](https://docs.internetcomputer.org/guides/authentication/internet-identity). |
| 6 | + |
| 7 | +Prerequisites and dev-container setup are covered in the [repository README](../README.md). |
| 8 | + |
| 9 | +## Getting started |
| 10 | + |
| 11 | +- [`hello_world`](hello_world/) — full-stack "Hello, world!" with a Rust backend and a Vite frontend. |
| 12 | +- [`backend_only`](backend_only/) — the minimal canister: a single `greet` query function, no frontend. |
| 13 | +- [`backend_wasm64`](backend_wasm64/) — the same minimal canister compiled for the Wasm64 target. |
| 14 | +- [`who_am_i`](who_am_i/) — sign in with Internet Identity and see the principal your app receives. |
| 15 | + |
| 16 | +## Full-stack applications |
| 17 | + |
| 18 | +- [`daily_planner`](daily_planner/) — monthly calendar with notes and tasks; fetches historic facts via HTTPS outcalls. |
| 19 | +- [`flying_ninja`](flying_ninja/) — 2D side-scroller game with an on-chain leaderboard. |
| 20 | +- [`photo_gallery`](photo_gallery/) — upload and view photos served via the HTTP gateway with cacheable responses. |
| 21 | +- [`llm_chatbot`](llm_chatbot/) — chat with a large language model from a canister. |
| 22 | + |
| 23 | +## Tokens and payments |
| 24 | + |
| 25 | +- [`icp_transfer`](icp_transfer/) — hold ICP in a canister and send it to other accounts via the ICP ledger. |
| 26 | +- [`receiving-icp`](receiving-icp/) — generate account identifiers and check balances to receive ICP. |
| 27 | +- [`exchange-rates`](exchange-rates/) — query crypto and fiat exchange rates from the Exchange Rate Canister (XRC). |
| 28 | +- [`stake_neuron_from_cli`](stake_neuron_from_cli/) — stake ICP into an NNS neuron from a Rust CLI binary using `ic-agent`. |
| 29 | + |
| 30 | +## Chain fusion and signing |
| 31 | + |
| 32 | +- [`basic_bitcoin`](basic_bitcoin/) — send and receive Bitcoin (P2PKH, P2WPKH, P2TR addresses). |
| 33 | +- [`basic_ethereum`](basic_ethereum/) — send and receive Ether using threshold ECDSA. |
| 34 | +- [`evm_block_explorer`](evm_block_explorer/) — fetch block data from Ethereum and other EVM chains via the EVM RPC canister. |
| 35 | +- [`threshold-ecdsa`](threshold-ecdsa/) — a threshold ECDSA signing oracle. |
| 36 | +- [`threshold-schnorr`](threshold-schnorr/) — a threshold Schnorr (BIP340/BIP341, Ed25519) signing oracle. |
| 37 | +- [`x509`](x509/) — issue and verify X.509 certificates with threshold signatures. |
| 38 | + |
| 39 | +## HTTPS outcalls |
| 40 | + |
| 41 | +- [`send_http_get`](send_http_get/) — make a `GET` request to an external API from a canister. |
| 42 | +- [`send_http_post`](send_http_post/) — make a `POST` request to an external API from a canister. |
| 43 | + |
| 44 | +## Inter-canister patterns |
| 45 | + |
| 46 | +- [`inter-canister-calls`](inter-canister-calls/) — bounded-wait and unbounded-wait calls, retries, and attaching cycles. |
| 47 | +- [`parallel_calls`](parallel_calls/) — parallel vs. sequential inter-canister calls. |
| 48 | +- [`composite_query`](composite_query/) — query functions that call other canisters' queries. |
| 49 | +- [`guards`](guards/) — how guard functions interact with asynchronous code. |
| 50 | +- [`candid_type_generation`](candid_type_generation/) — generate Rust types from an external canister's `.did` file. |
| 51 | + |
| 52 | +## Canister operations and system features |
| 53 | + |
| 54 | +- [`canister-info`](canister-info/) — retrieve metadata about any canister via the management canister. |
| 55 | +- [`canister-snapshots`](canister-snapshots/) — take and restore canister snapshots. |
| 56 | +- [`canister-snapshot-download`](canister-snapshot-download/) — download and upload canister snapshots. |
| 57 | +- [`canister_logs`](canister_logs/) — canister logging, traps, panics, and error handling. |
| 58 | +- [`low_wasm_memory`](low_wasm_memory/) — react to low Wasm memory with the `on_low_wasm_memory` hook. |
| 59 | +- [`periodic_tasks`](periodic_tasks/) — timers and heartbeats for scheduled execution. |
| 60 | +- [`performance_counters`](performance_counters/) — measure the work a canister performs. |
| 61 | +- [`query_stats`](query_stats/) — read a canister's own query statistics. |
| 62 | + |
| 63 | +## Compute and AI |
| 64 | + |
| 65 | +- [`image-classification`](image-classification/) — run an ONNX machine-learning model inside a canister. |
| 66 | +- [`face-recognition`](face-recognition/) — face detection and recognition with the Tract ONNX engine. |
| 67 | +- [`qrcode`](qrcode/) — long-running image processing in a single message execution. |
| 68 | +- [`simd`](simd/) — WebAssembly SIMD acceleration for compute-heavy workloads. |
| 69 | + |
| 70 | +## Testing |
| 71 | + |
| 72 | +- [`unit_testable_rust_canister`](unit_testable_rust_canister/) — structure a canister for comprehensive unit testing. |
| 73 | + |
| 74 | +## Encryption with vetKeys |
| 75 | + |
| 76 | +The [`vetkeys/`](vetkeys/) directory contains examples for [vetKeys](https://docs.internetcomputer.org/concepts/vetkeys), from the low-level API to complete applications: [`basic_vetkd`](vetkeys/basic_vetkd/), [`basic_ibe`](vetkeys/basic_ibe/), [`basic_timelock_ibe`](vetkeys/basic_timelock_ibe/), [`basic_bls_signing`](vetkeys/basic_bls_signing/), [`password_manager`](vetkeys/password_manager/), [`password_manager_with_metadata`](vetkeys/password_manager_with_metadata/), and [`encrypted_notes_app_vetkd`](vetkeys/encrypted_notes_app_vetkd/). |
| 77 | + |
| 78 | +## Security considerations and best practices |
| 79 | + |
| 80 | +If you base your application on one of these examples, we recommend you familiarize yourself with and adhere to the [security best practices](https://docs.internetcomputer.org/guides/security/overview) for developing on the Internet Computer. The examples provided here may not implement all the best practices. |
0 commit comments