Skip to main content

Vara Examples

This section contains a set of examples that can be used for familiarization with writing programs on Vara or as the basis for dApps: https://github.com/gear-foundation.

Programs can be written from scratch or built from provided examples.

Stable Environment

All program examples and JS applications have been tested in a stable environment with specific development tool versions necessary for implementing, building, and running programs and JS applications.

A local development environment can be configured according to the information provided below or by using a pre-configured Docker image as described in the Using Docker section.

Current stable release: v1.4.2

Compiler ToolsVersionHow to install / access
Linux users should generally install GCC and Clang, according to their distribution’s documentation.Latest

For example, on Ubuntu use:

sudo apt install -y build-essential clang cmake

On macOS, install a compiler toolset by running:

xcode-select --install
Ruststable
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Add Wasm target to the toolchain:

rustup target add wasm32-unknown-unknown
Gear Rust libraries: gstd, gtest, gmeta, gclient, gear-wasm-builderv1.4.2

Ensure the correct version is tagged in the Cargo.toml file of the program in use. For example: https://github.com/gear-foundation/dapps/blob/master/contracts/Cargo.toml

Vara Network Testnet1.4.2

Ensure connection to the Vara Network Testnet. Switch networks by clicking on the network name in https://idea.gear-tech.io

Gear JS ToolsVersionHow to install / access
Gear JS API0.38.1Ensure this version is specified in the package.json file of the program repository
Gear JS React Hooks0.10.7Ensure this version is specified in the package.json file of the program repository
Gear JS UI Kit0.5.24Ensure this version is specified in the package.json file of the program repository
Note

Windows users may encounter problems related to the installation of Rust components and dependencies. It is highly recommended to use Linux or macOS for compiling Vara nodes and programs.

Environment Versions History

Previous Environment Versions

Vara node versionRuntime versionGear libraries versionRust toolchain version
v1.4.21420tag = "v1.4.2"stable
v1.4.11410tag = "v1.4.1"stable
v1.4.01400tag = "v1.4.0"stable
v1.3.11310tag = "v1.3.1"stable
v1.2.11210tag = "v1.2.1"stable
v1.1.11110tag = "v1.1.1"stable
v1.0.51050tag = "v1.0.5"nightly-2023-09-18
v1.0.21020tag = "v1.0.2"nightly-2023-10-14
v1.0.11010tag = "v1.0.1"nightly-2023-10-14
v1.0.01000tag = "v1.0.0"nightly-2023-04-25
v0.3.3330tag = "v0.3.3"nightly-2023-04-25
v0.2.2220rev = "946ac47"nightly-2023-04-25
v0.1.6160rev = "78dfa07"nightly-2023-04-25
v0.1.4140rev = "5c685d0"nightly-2023-03-14

First Steps

To create an app project, use the command cargo:

cargo new gear-app --lib

The project structure will be as follows:

  └── gear-app // Program directory

├── src // Source files of the program
│ ├── maybe_some_file.rs // Additional module if needed
│ └── lib.rs // Main file of the program

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

Create a file build.rs with the following code:

fn main() {
gear_wasm_builder::build();
}

Cargo.toml is a project manifest in Rust, containing all metadata necessary for compiling the project. Configure the Cargo.toml similarly to how it is configured in dapp-template/Cargo.toml. Refer to Getting Started for additional details.

Building Rust Program

Compile the program in the app folder:

cargo build --release

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

Using Docker

A pre-configured Docker image can be used to build and test programs. The image contains all necessary tools and dependencies for building and running programs and JS applications.

The source code of the image is available on GitHub.

To use the image, install Docker on the machine. Installation instructions for different operating systems are available on the Docker website.

After installing Docker, pull the image from Docker Hub:

docker pull ghcr.io/gear-foundation/gear-env:stable

Run the image with the following command:

docker run --rm --name gear-env -itd ghcr.io/gear-foundation/gear-env:stable bash

The command will run the image in the background and provide access to the container's shell. Access the container's shell with:

docker exec -it gear-env bash

Copy a program to be built to the container (use the gear-app created above):

docker cp ./gear-app gear-env:/root

Build the program:

docker exec -itw /root/gear-app gear-env cargo build --release

The compiled program will be available in the target/wasm32-unknown-unknown/release folder inside the container. Copy it to the local machine:

docker cp gear-env:/root/gear-app/target/wasm32-unknown-unknown/release/. ./

Stop the Docker container after use:

docker stop gear-env