Phat Contract Examples

This repo provides examples that demonstrate Phala phat contract features.

Environment Preparation

An operating system of macOS or Linux systems like Ubuntu 18.04/20.04 is recommended for the workshop.

  • For macOS users, we recommend to use the Homebrew package manager to install the dependencies
  • For other Linux distribution users, use the package manager with the system like Apt/Yum

The following toolchains are needed:

  • Rust toolchain
    • Install rustup, rustup is the "package manager" of different versions of Rust compilers: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    • This will install rustup and cargo
  • Ink! Contract toolchain
    • Install binaryen with
      • Homebrew for macOS: brew install binaryen
      • Apt for Ubuntu: sudo apt install binaryen
      • or download the release and put it under your $PATH
    • Install dylint-link toolchain: cargo install cargo-dylint dylint-link
    • Install contract toolchain: cargo install cargo-contract --force
    • For macOS M1 chip users: rustup component add rust-src --toolchain nightly-aarch64-apple-darwin
  • Install frontend toolchain

Check your installation with

$ rustup toolchain list
# stable-x86_64-unknown-linux-gnu (default)
# nightly-x86_64-unknown-linux-gnu

$ cargo --version
# cargo 1.58.0 (f01b232bc 2022-01-19)

$ cargo contract --version
# cargo-contract 0.17.0-unknown-x86_64-linux-gnu

$ node --version
# v17.5.0

$ yarn --version
# 1.22.17

Build

Clone this repo and go to any subdirectory then make, or cargo contract build --release if there isn't a Makefile.

For example:

git clone https://github.com/Phala-Network/phat-contract-examples.git
cd phat-contract-examples/mqtt-broker
make
cd ../logging
cargo contract build --release