Build
Getting Started
First contract

First contract

This section introduces how to use Rooch CLI to create a Move contract.

Create project

rooch move new hello_rooch

After executing this Rooch CLI command, a Rooch contract project will be created and automatically initialized. The root directory of the project contains a sources directory for storing the Move contract code, and a manifest file named Move.toml for declaring the current project. The name, version, address alias (named address) and project dependencies.

Contents of the Move.toml file of the hello_rooch project:

[package]
name = "hello_rooch"
version = "0.0.1"
 
[dependencies]
MoveStdlib = { git = "https://github.com/rooch-network/rooch.git", subdir = "frameworks/move-stdlib", rev = "main" }
MoveosStdlib = { git = "https://github.com/rooch-network/rooch.git", subdir = "frameworks/moveos-stdlib", rev = "main" }
RoochFramework = { git = "https://github.com/rooch-network/rooch.git", subdir = "frameworks/rooch-framework", rev = "main" }
 
[addresses]
hello_rooch = "0xbc34dd9a140ab26f88f466c9ea7ea14507bc2795dcfd4b6c7ac694dd3c2e1c8d"
std = "0x1"
moveos_std = "0x2"
rooch_framework = "0x3"

Write a contract

We simply write a Move contract to demonstrate storing a "Hello Rooch!" string into Rooch's account storage.

module hello_rooch::hello_rooch {
    use moveos_std::account;
    use std::string;

    struct HelloMessage has key {
        text: string::String
    }

    entry fun say_hello(owner: &signer) {
        let hello = HelloMessage { text: string::utf8(b"Hello Rooch!") };
        account::move_resource_to(owner, hello);
    }
}

Define a HelloMessage type, which is a structure containing a text field.

Then define an entry function say_hello, build a resource instance that stores Hello Rooch!, and move it to the account storage.