Skip to main content

Gear Examples

Gear provides a set of examples that can be used for your familiarization with writing programs on Gear or become the basis for your own dApp:

You can write your own smart contract or try to build from examples. Let's Rock!


To develop your first Rust smart-contract you would have to install some components.


Windows users may encounter some problems related to the installation of Rust components and dependencies. It is highly recommended to use Linux or macOS for compiling Gear node and smart-contracts.

  • Linux users should generally install GCC and Clang, according to their distribution’s documentation. Also, one should install binaryen toolset that contains required wasm-opt tool.

    • For example, on Ubuntu use:
      sudo apt install -y clang build-essential binaryen cmake protobuf-compiler
    • On macOS, you can get a compiler toolset and binaryen by running:
      xcode-select --install
      brew install binaryen
  • Install Rustup:

    curl --proto '=https' --tlsv1.2 -sSf | sh
  • Add Wasm target to your toolchain:

    rustup toolchain add nightly
    rustup target add wasm32-unknown-unknown --toolchain nightly

First steps

To create our app project use the command cargo:

cargo new gear-app --lib

The project structure is following:

  └── gear-app // Your contract dir

├── src // Source files of your program
│ ├── // Additional module if needed
│ └── // Main file of your program

└── Cargo.toml // Manifest of your program

Create file with the following code:

fn main() {

Cargo.toml is a project manifest in Rust, it contains all metadata necessary for compiling the project. Configure the Cargo.toml similarly to how it is configured ping/Cargo.toml. You can refer to Getting Started for additional details.

Building Rust Contract

We should compile our smart contract in the app folder:

cargo build --release

Our application should compile successfully and the final file target/wasm32-unknown-unknown/release/gear-app.wasm should appear.