dfinity/examples

repository·master·Indexed 20 days ago

https://github.com/dfinity/examples

A collection of sample applications for the Internet Computer (ICP) to help developers build, deploy, and integrate canisters with frontends and native applications. Includes templates for hosting static websites, React frontends, Godot HTML5 and Unity WebGL game exports, a photo storage example using AssetManager, the OISY Signer Demo for ICRC-1 transfers, and Motoko backend-only implementations.

Tokens
109.9K
Snippets
395
Records
547
Agent score
67%

What's inside dfinity-examples

  1. Overview of FileVault

    master

    FileVault is a file storage application designed for the Internet Computer. It enables users to upload, download, and delete files from their local computers to the network.

    Key features include:

    • Authentication: Uses Internet Identity (II) for user login.
    • Privacy: Files are stored under the user's Internet Identity principal, ensuring that only the owner can access their files via the canister's public interface.
  2. Overview of the EVM Block Explorer

    master
    The EVM Block Explorer demonstrates how an Internet Computer (ICP) canister can fetch block data directly from Ethereum and other EVM-compatible chains. It achieves this by using HTTPS outcalls via the EVM RPC canister, allowing canisters to read on-chain data without requiring a bridge or an oracle. This pattern is applicable to any EVM-compatible chain supported by the EVM RPC canister.
  3. Overview of Basic VetKD Demo (Rust)

    master

    This example demonstrates the raw VetKD management canister API, which serves as the lowest-level building block for verifiably encrypted threshold key derivation on the Internet Computer. It provides direct access to the management canister interface without SDK abstractions.

    Key use cases demonstrated include:

    • Symmetric key derivation: Using AES-GCM-256.
    • Identity-Based Encryption (IBE).

    Note: This is a low-level implementation. For a higher-level developer experience, use the @icp-sdk/vetkeys SDK found in other examples within the vetkeys/ directory.

  4. Overview of the Photo Storage example

    master
    The Photo Storage example demonstrates how to store photos on the Internet Computer (ICP) using an asset canister. It utilizes the AssetManager from the @icp-sdk/canisters/assets package. In this architecture, the application is deployed as a frontend within an asset canister, which is simultaneously used for handling photo uploads.
  5. Overview of Basic IBE (Identity-Based Encryption)

    master

    The Basic IBE example demonstrates how to use VetKeys to implement secure messaging on the Internet Computer (IC).

    Core Concepts

    • Secure Messaging: Uses VetKeys IBE capabilities to encrypt messages that only the intended recipient can decrypt.
    • Principal-Based Encryption: Messages are encrypted using the recipient's Internet Identity Principal as the public key identifier.
    • Private Key Management: Private decryption keys are generated via the VetKD protocol and encrypted using the user's transport key. This ensures the canister itself cannot access the private keys; it only sees and forwards them in encrypted form.
  6. Overview of Basic Timelock IBE

    master

    The Basic Timelock IBE example demonstrates a secret-bid auction implementation using VetKeys on the Internet Computer.

    Core Functionality

    • Secret Bid Placement: Uses Identity-Based Encryption (IBE) to encrypt messages that can only be decrypted by the intended recipient after a specific time period has elapsed.
    • Bid-Id-Based Encryption: Each bid is assigned a unique bid ID, which serves as the public key identifier for the ciphertext.
    • Time-Based Access Control: The canister ensures bids remain secret until the auction lot closes. Once closed, the canister's internal timer triggers decryption.

    Auction Rules

    1. Lot Creation: Authenticated users (via Internet Identity) create auction lots with a description and a deadline.
    2. Bidding: Users can place one secret bid per lot. If multiple bids are provided by the same user, only the last one is considered. Bids for expired lots or unexpectedly large ciphertexts are rejected.
    3. Winner Selection: Once the lot closes, the canister decrypts the secret bids. The highest bidder wins; if there is a tie, the bid placed earliest wins.
    4. Transparency: Because the canister performs the decryption, it is critical that the canister's code is public so users can verify that decryption only occurs according to the intended rules (e.g., only after the lot is closed).
  7. Overview of the Hello World example

    master

    This example demonstrates a simple Internet Computer (ICP) application consisting of a Rust backend canister and a frontend UI.

    Backend Functionality: The backend canister uses stable memory to persist a customizable greeting prefix (defaulting to "Hello, "). It exposes two primary methods:

    • set_greeting(prefix): Updates the greeting prefix. This value is persisted across canister upgrades.
    • greet(name): Returns the combined greeting and the provided name (e.g., "Hello, World!").

    Frontend Functionality: A simple web interface allows users to input a name and receive the personalized greeting from the canister.

  8. What is the Who am I? example?

    master

    The 'Who am I?' example demonstrates how entities (users or canister smart contracts) are identified on the Internet Computer using Principals.

    It uses Internet Identity (II) to authenticate users and then retrieves and displays the Principal identifier associated with that Internet Identity on the user interface.

  9. Overview of Basic VetKD Demo (Motoko)

    master

    This sample demonstrates the raw VetKD management canister API, which serves as the lowest-level building block for verifiably encrypted threshold key derivation on the Internet Computer.

    It showcases two primary use cases:

    1. Symmetric key derivation: Using AES-GCM-256.
    2. Identity-Based Encryption (IBE).

    Note that this example interacts directly with the management canister interface without SDK abstractions. For a higher-level implementation, use the @icp-sdk/vetkeys SDK found in other vetkeys/ examples.

  10. Overview of the Photo Gallery application

    master

    The Photo Gallery is a demo application built on the Internet Computer designed to showcase how the ic-http-certification crate and the HTTP gateway can serve images with long-lived Cache-Control headers.

    Backend Capabilities

    The backend canister stores images in memory and provides the following API:

    • upload_image(name, content_type, data): Stores an image blob and returns its numeric ID.
    • list_images(): Returns metadata (ID, name, content type) for all stored images.
    • http_request(request): Serves images at /image/<id> via the HTTP gateway. It uses skip-certification headers to allow the HTTP gateway to bypass response verification, which is suitable for public, immutable content. It also includes Cache-Control: public, max-age=31536000, immutable for browser caching.

    Frontend Capabilities

    The frontend is a React + Vite application that allows users to upload images and renders the gallery by constructing HTTP gateway URLs for each image ID, enabling direct browser fetching and caching.