Build
Getting Started
First contract
Quick start

Quick start

This section will quickly introduce the development of Rooch through a counter example.

What is counter

The counter is a small counting program. It contains an initial value. We can increment its value through an increment instruction to achieve the purpose of counting.

We can use any programming language to implement this small program. This tutorial will use the Move language to write it and let it run successfully on Rooch.

Create counter project

Before we create the counter contract program, we can use the CLI command provided by Rooch to initialize an empty project:

rooch move new quick_start_counter

For detailed methods, please refer to Creating a Rooch Move Contract.

Next, create a counter.move file in the sources directory to write our contract code.

Contract writing

module quick_start_counter::quick_start_counter {
    use moveos_std::account;

    struct Counter has key {
        count_value: u64
    }

    fun init(account: &signer) {
        account::move_resource_to(account, Counter { count_value: 0 });
    }

    entry fun increase() {
        let counter = account::borrow_mut_resource<Counter>(@quick_start_counter);
        counter.count_value = counter.count_value + 1;
    }
}

With a simple 16 lines of code, a simple counter function is implemented on Rooch Move.

What follows is a detailed description of what each line of code does.

Module declaration

In the Move language, contracts are usually written in modules. Simple contracts can be completed through one module, while complex contracts may be composed of multiple modules. Our counter contract is very simple, so there is only one quick_start_counter module.

Modules usually contain data types and functions required to implement the current module functions.

module quick_start_counter::quick_start_counter {

In line 1, we declare a quick_start_counter module using the module keyword.

In the Move-based blockchain system, modules are uniquely identified by address, that is, an address can only have one module with the same name, and modules with the same name cannot be published multiple times. The same contract can be published by multiple addresses. In order to identify who published the contract module in the blockchain system, it needs to be uniquely identified by the address.

Therefore, the syntax for declaring a Move module is module address::module_name.

Import module

use moveos_std::account;

In line 2, the use keyword modifies the statement that imports the module. To implement the counter contract on Rooch, we need to use some of Rooch's function libraries. This contract uses the account module provided by the MoveOS standard library.

Define data structure

struct Counter has key {
    count_value: u64
}

We define a Counter type structure to record the count value. The structure only contains a u64 type field count_value.

We want to record the value of the Counter type into Rooch's global storage, so we need to provide a key ability for this type so that Move can find the data through the key.

Initialization function

fun init(account: &signer) {
    account::move_resource_to(account, Counter { count_value: 0 });
}

Move provides a specific initialization function init to automatically initialize the contract to ensure that some necessary operations have been performed after the contract is released.

For example, we hope that once the counter contract is released, the contract will automatically initialize the counter for us so that its count value is 0.

Line 8 is the function signature of the init function, which accepts an account parameter.

Increasing function

Next, we need to define an incrementing function that will increment the counter value by 1 every time it is executed.

entry fun increase() {
    let counter = account::borrow_mut_resource<Counter>(@quick_start_counter);
    counter.count_value = counter.count_value + 1;
}

Line 12 is the signature of the increase function.

In line 14, the borrow_mut_resource instruction of the account storage provided by Rooch is called to obtain a mutable reference of type Counter, and the return value of the function is bound to the counter variable. By borrowing a mutable reference from Counter, we can modify its value.

The borrow_mut_resource function has an address parameter to borrow the Counter resource. For simplicity, we directly use the address of the publishing counter module as the borrower.

In line 14, we obtain the field value of the Counter structure through member operations and perform an increment operation.

At this point, we have implemented the incrementing logic of the counter.

Entry function

The entry function is a function modified by the entry keyword.

For security reasons, the Move virtual machine prohibits external (command line, etc.) direct calls to functions that operate module data. Instead, a method called an entry function is provided to indirectly call logical functions. The entry function is the contract exposed to the outside what an interface.

Note: In order to simplify the counter contract demonstrated in this example as much as possible, we merged the logical operation and entry function into one increase function. In actual development, it is recommended to encapsulate the logic and entry function separately into different functions.

As you can see, the increase function on line 12 is modified with the entry keyword, so it becomes an entry function. With the entry function, we can perform the counter increment operation in the command line or other clients.

Demo counter program in Rooch's CLI

  1. First check whether the currently activated Rooch network is the dev network:
$ rooch env list
 
       Env Alias         |                     RPC URL                      |                  Websocket URL                   |  Active Env
---------------------------------------------------------------------------------------------------------------------------------------------------------
         local           |               http://0.0.0.0:50051               |                       Null                       |
          dev            |       https://dev-seed.rooch.network:443/        |                       Null                       |     True

Note that if the dev environment of Active Env is not True, use the rooch env switch --alias dev command to switch to the development network.

  1. Open another terminal, switch to the root directory of the counter project, and compile the contract:
[joe@mx quick_start_counter]$ rooch move build
 
UPDATING GIT DEPENDENCY https://github.com/rooch-network/rooch.git
UPDATING GIT DEPENDENCY https://github.com/rooch-network/rooch.git
UPDATING GIT DEPENDENCY https://github.com/rooch-network/rooch.git
INCLUDING DEPENDENCY MoveStdlib
INCLUDING DEPENDENCY MoveosStdlib
INCLUDING DEPENDENCY RoochFramework
BUILDING quick_start_counter
Success
  1. Publish the counter contract to Rooch:
[joe@mx quick_start_counter]$ rooch move publish
 
UPDATING GIT DEPENDENCY https://github.com/rooch-network/rooch.git
UPDATING GIT DEPENDENCY https://github.com/rooch-network/rooch.git
UPDATING GIT DEPENDENCY https://github.com/rooch-network/rooch.git
INCLUDING DEPENDENCY MoveStdlib
INCLUDING DEPENDENCY MoveosStdlib
INCLUDING DEPENDENCY RoochFramework
BUILDING quick_start_counter
 
Publish modules to address: 0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7
{
  "sequence_info": {
    "tx_order": "997",
    "tx_order_signature": {
      "auth_validator_id": "0",
      "payload": "0x00f77ea5b2c79f9d18813d1a355040cd0d7edeed0773cf8ec055c9bb7728b8858b2bb817c7f219544f488a9908ea6be3e5d0b01341920e755766ff1e287a866e03ca2ecf17ab26b7c32ddba10913e6f74d43b5258905bef0f88b6d744d73bc9ce9"
    },
    "tx_accumulator_root": "0xebb1ce9e45ad2122a7f6260275c5eec4fb0f8c827e8e3fcdbab3001aa0b66847"
  },
  "execution_info": {
    "tx_hash": "0x25e0647cf5d7b2824b7b7fa8ba561804869e8f097c18ae00d45da449bd9eaddd",
    "state_root": "0x5689c932ff3383b4fd6f0bedaf454e0ac6d1c21e2a28b158749bb808c95160ab",
    "event_root": "0x16bb2251e4ecb63bfa514b21cac7b2fff73a4ddac5174148b19eac4140636da4",
    "gas_used": 1752492,
    "status": {
      "type": "executed"
    }
  },
  "output": null
}

When you see executed in the execution_info.status of the output result, it means that the counter contract has been successfully released and the counter has been initialized.

  1. We use the resource search command provided by Rooch to obtain information about Counter resources.

The syntax is rooch resource --address address_of_published_resource --resource resource_type:

[joe@mx ~]$ rooch resource --address 0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7 --resource 0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::quick_start_counter::Counter
 
{
  "value": "0x0000000000000000",
  "value_type": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::quick_start_counter::Counter",
  "decoded_value": {
    "abilities": 8,
    "type": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::quick_start_counter::Counter",
    "value": {
      "count_value": "0"
    }
  },
  "display_fields": null
}

Pay attention to the value attribute. You can see that in the output information of the Counter resource, the field count_value of Counter is indeed 0.

  1. Then we call the counter’s increment function:

The syntax is rooch move run --function address_published_by_the_module::module_name::entry_function_name --sender-account address_to_send_the_current_transaction.

Note: In the blockchain system, performing certain operations is usually performed by sending a transaction to the blockchain system to perform the corresponding operation.

[joe@mx ~]$ rooch move run --function 0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::quick_start_counter::increase --sender-account 0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7
 
{
  "sequence_info": {
    "tx_order": "1010",
    "tx_order_signature": {
      "auth_validator_id": "0",
      "payload": "0x00e49e8780b71610f7e5160b06b6481612547374a15af6a66e2d7e32a028443e907ab41ab068b4c83ba0253cc84dd9bc170e3ff09eced73b6564089b74a930c500ca2ecf17ab26b7c32ddba10913e6f74d43b5258905bef0f88b6d744d73bc9ce9"
    },
    "tx_accumulator_root": "0xfa6ad39423cc3070a46c5db5b20e6cdda3c1070afd9a81401ccaee1e4998b9fd"
  },
  "execution_info": {
    "tx_hash": "0x2f5b18d14d31441ab48b683c8e7ea650363bf822f4e8721004884eda29c96440",
    "state_root": "0x75f3cb5e0c14660db68280c67301adec769f59264f081d06c1ff92d493bbaa74",
    "event_root": "0xc6b4ac8ed511911965caca540fdedeef87db64d6ae29f58a874161630d219d5e",
    "gas_used": 670730,
    "status": {
      "type": "executed"
    }
  },
  "output": null
}

If you see executed in the status, it proves that the increase function call was successful.

  1. Check again to see if the counter value is what we expected:
[joe@mx ~]$ rooch resource --address 0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7 --resource 0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::quick_start_counter::Counter
{
  "value": "0x0100000000000000",
  "value_type": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::quick_start_counter::Counter",
  "decoded_value": {
    "abilities": 8,
    "type": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::quick_start_counter::Counter",
    "value": {
      "count_value": "1"
    }
  },
  "display_fields": null
}

As you can see, the value of the Counter's value field has indeed been updated to 1.

At this point, you already know how to write contracts in Rooch and how to call contracts from the command line.

Quick experience

The source code of this example is stored in the rooch/examples/quick_start_counter directory. To make testing easier, we change the address in the Move.toml file to the wildcard character _.

If you run it directly using the example we provided, the executed Shell command will be a little different:

$ rooch move build --named-addresses quick_start_counter=default
 
$ rooch move publish --named-addresses quick_start_counter=default
 
# 注意 `0xc4a286bef174e126ef24363a0799c069504d0f132f713bf4762ad127c799df81` 是我演示的地址,当你实际运行时,需要更改为你自己的钱包地址
$ rooch resource --address 0xc4a286bef174e126ef24363a0799c069504d0f132f713bf4762ad127c799df81 --resource 0xc4a286bef174e126ef24363a0799c069504d0f132f713bf4762ad127c799df81::quick_start_counter::Counter
 
$ rooch move run --function 0xc4a286bef174e126ef24363a0799c069504d0f132f713bf4762ad127c799df81::quick_start_counter::increase --sender-account default
 
$ rooch resource --address 0xc4a286bef174e126ef24363a0799c069504d0f132f713bf4762ad127c799df81 --resource 0xc4a286bef174e126ef24363a0799c069504d0f132f713bf4762ad127c799df81::quick_start_counter::Counter

Note: The default in the command represents the default address in the Rooch configuration. If you want to use another address, you can also directly pass the address starting with 0x.

Object-oriented storage model

Above we used the account's resource storage model to simply implement and use counter. Next we will introduce another storage model -- the object storage model.

We will refactor the counter example and demonstrate it on Rooch's dev network.

Initialize project

Create a Move project named quick_start_object_counter:

rooch move new quick_start_object_counter

Here is the counter code after refactoring:

module quick_start_object_counter::quick_start_object_counter {
    use std::signer;
    use moveos_std::event;
    use moveos_std::object::{Self, Object, ObjectID};

    struct Counter has key, store {
        count_value: u64
    }

    struct UserCounterCreatedEvent has drop {
        id: ObjectID
    }

    fun init(owner: &signer) {
        create_shared();
        create_user(owner);
    }

    fun create_shared() {
        let counter = Counter { count_value: 0 };
        let counter_obj = object::new_named_object(counter);
        object::to_shared(counter_obj);
    }

    fun create_user(owner: &signer): ObjectID {
        let counter = Counter { count_value: 123 };
        let owner_addr = signer::address_of(owner);
        let counter_obj = object::new(counter);
        let counter_obj_id = object::id(&counter_obj);
        object::transfer(counter_obj, owner_addr);
        let user_counter_created_event = UserCounterCreatedEvent { id: counter_obj_id };
        event::emit(user_counter_created_event);
        counter_obj_id
    }

    public entry fun increase(counter_obj: &mut Object<Counter>) {
        let counter = object::borrow_mut(counter_obj);
        counter.count_value = counter.count_value + 1;
    }
}

Explain

We will use some libraries provided by Move and MoveOS, and the signer module to obtain the address of the signed transaction. The event module handles events, which is mainly used to mark events of object creation.

Define two data structures, Counter stores the value of the counter, and UserCounterCreatedEvent stores the ID of the counter object.

Similarly, we define init to call the logical function that creates the counter. You can see that we call two functions: create_shared and create_user respectively. In this example, we demonstrate the differences and functions of the two types of objects in Rooch's object storage model.

The create_shared function encapsulates the logic of creating a shared counter. It creates a counter that all users can increment. First construct a counter with an initial value of 0. Then call the new_named_object function to create a named object. This counter is globally unique, so we can query its related properties directly through the type. Finally, we call the to_shared function to change the counter object into It is shared so that any account can modify its value.

The create_user function encapsulates the logic of creating an ordinary counter. The value of this counter can only be modified by the creator. First, we construct a counter with an initial value of 123, and then obtain the address of the signed transaction. Use the new_object function to create a counter object and get the ID of the counter object. Then, call the transfer function to transfer the counter object to the account address that signed the transaction, thus completing the creation of the counter object. In order to get the ID of a counter object on the command line and use it to increment the counter, we need to send a message with the help of an event.

The increase entry function encapsulates our logic for incrementing the counter. First, call borrow_mut to obtain a mutable reference to the counter from the counter object, and then perform a +1 operation on the count value.

Prerequisites

To demonstrate this example, we need to prepare two Rooch accounts.

You can use the rooch account create command to create an account, use the rooch account switch command to switch accounts, and use the rooch account list command to list the currently existing account list.

                     Rooch Address (Ed25519)                       |               Public Key (Base64)                | Auth Validator ID | Active Address
---------------------------------------------------------------------------------------------------------------------------------------------------------
0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63 |   AP/7lMzNiiFOSk6AWrYlozVau+5dBukK5nLt9ei6DE4N   |        0         |     True
0xd9ba8633a96c91eea2c180e23e8cca8bb8cfd438764143d7ca4753c3e2b7f5fe |   AIF6/NuwAcH3nSgETrAt51ppZyE3RlSKxe5eWqaBNKNG   |        0         |

Next, I will use these two accounts to demonstrate this example. The address starting with 0x94bfa is used as the account address for publishing the counter contract, and the account starting with 0xd9ba8 is used as other users to operate the shared counter.

Demo

  1. Compile and deploy
rooch move publish --named-addresses quick_start_object_counter=default
  1. Get the counter object ID owned by the user:
curl --location --request POST 'https://dev-seed.rooch.network:443' --header 'Content-Type: application/json' --data-raw '{
 "id":101,
 "jsonrpc":"2.0",
 "method":"rooch_getEventsByEventHandle",                                                                                                                       "params":["0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::UserCounterCreatedEvent", null, "1000", {"decode":true}]
}'|jq '.result.data[0].decoded_event_data.value.id'

Use curl to send a request to the Rooch development network to obtain the counter object ID created in the contract just deployed.

Note: The address in the parameter list must be changed to your own. My default account address is 0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63.

You can later see in the response information that the counter object ID is 0x09dd7a2f60fda09c7e9009041b36742109911fe79b0240a0badc07fc800fc4c2, which is randomly generated when the counter object is created.

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   922  100   683  100   239   2831    990 --:--:-- --:--:-- --:--:--  3841
 
"0x09dd7a2f60fda09c7e9009041b36742109911fe79b0240a0badc07fc800fc4c2"
  1. Check the two counters we created and initialized separately.
  • Shared counter:

The command to view the counter object is rooch object --id CONTRACT_ADDRESS::MODULE_NAME::TYPE_NAME. Because named objects are globally unique, we can use the type name to directly obtain the related properties of the shared counter object.

[joe@mx quick_start_object_counter]$ rooch object --id 0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter
 
{
  "value": "0x5d6b1f08e259030c7493b7b4b0f78a390cf3eb81b720d5ef123a6f7ba794c3880000000000000000000000000000000000000000000000000000000000000000010000000000000000",
  "value_type": "0x2::object::ObjectEntity<0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter>",
  "decoded_value": {
    "abilities": 0,
    "type": "0x2::object::ObjectEntity<0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter>",
    "value": {
      "flag": 1,
      "id": "0x5d6b1f08e259030c7493b7b4b0f78a390cf3eb81b720d5ef123a6f7ba794c388",
      "owner": "0x0000000000000000000000000000000000000000000000000000000000000000",    <= Note here!
      "value": {
        "abilities": 12,
        "type": "0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter",
        "value": {
          "count_value": "0"    <= Note here!
        }
      }
    }
  }
}

You can see that the owner address of the shared counter is 0x00000000000000000000000000000000000000000000000000000000000000, which represents an object of SystemOwnedObject type, and its count value count_value is also initialized to 0.

  • Counters owned by user:
[joe@mx quick_start_object_counter]$ rooch object --id 0x09dd7a2f60fda09c7e9009041b36742109911fe79b0240a0badc07fc800fc4c2
 
{
  "value": "0x09dd7a2f60fda09c7e9009041b36742109911fe79b0240a0badc07fc800fc4c294bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63007b00000000000000",
  "value_type": "0x2::object::ObjectEntity<0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter>",
  "decoded_value": {
    "abilities": 0,
    "type": "0x2::object::ObjectEntity<0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter>",
    "value": {
      "flag": 0,
      "id": "0x09dd7a2f60fda09c7e9009041b36742109911fe79b0240a0badc07fc800fc4c2",
      "owner": "0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63",    <= Note here!
      "value": {
        "abilities": 12,
        "type": "0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter",
        "value": {
          "count_value": "123"    <= Note here!
        }
      }
    }
  }
}

You can see that the owner address of the counter owned by the user is 0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63, which represents an object of UserOwnedObject type, and its count value count_value is also initialized to 123.

  1. Call the increase function to increment the counter.
  • Shared:

The syntax of the command is: rooch move run --function CONTRACT_ADDRESS::MODULE-NAME::FUNCTION_NAME --args object:CONTRACT_ADDRESS::MODULE_NAME::TYPE_NAME:

rooch move run --function 0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::increase --args object:0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter

Check:

[joe@mx quick_start_object_counter]$ rooch object --id 0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter
 
{
  "value": "0x5d6b1f08e259030c7493b7b4b0f78a390cf3eb81b720d5ef123a6f7ba794c3880000000000000000000000000000000000000000000000000000000000000000010100000000000000",
  "value_type": "0x2::object::ObjectEntity<0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter>",
  "decoded_value": {
    "abilities": 0,
    "type": "0x2::object::ObjectEntity<0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter>",
    "value": {
      "flag": 1,
      "id": "0x5d6b1f08e259030c7493b7b4b0f78a390cf3eb81b720d5ef123a6f7ba794c388",
      "owner": "0x0000000000000000000000000000000000000000000000000000000000000000",
      "value": {
        "abilities": 12,
        "type": "0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter",
        "value": {
          "count_value": "1"    <= Note here!
        }
      }
    }
  }
}

Indeed, as we expected, the count increased!

  • User owns:
rooch move run --function 0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::increase --args object:0x09dd7a2f60fda09c7e9009041b36742109911fe79b0240a0badc07fc800fc4c2

Check:

[joe@mx quick_start_object_counter]$ rooch object --id 0x09dd7a2f60fda09c7e9009041b36742109911fe79b0240a0badc07fc800fc4c2
{
  "value": "0x09dd7a2f60fda09c7e9009041b36742109911fe79b0240a0badc07fc800fc4c294bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63007c00000000000000",
  "value_type": "0x2::object::ObjectEntity<0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter>",
  "decoded_value": {
    "abilities": 0,
    "type": "0x2::object::ObjectEntity<0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter>",
    "value": {
      "flag": 0,
      "id": "0x09dd7a2f60fda09c7e9009041b36742109911fe79b0240a0badc07fc800fc4c2",
      "owner": "0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63",
      "value": {
        "abilities": 12,
        "type": "0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter",
        "value": {
          "count_value": "124"    <= Note here!
        }
      }
    }
  }
}

The value of the user-owned counter changed from 123 to 124.

  1. Switch accounts:
[joe@mx ~]$ rooch account switch --address 0xd9ba8633a96c91eea2c180e23e8cca8bb8cfd438764143d7ca4753c3e2b7f5fe
The active account was successfully switched to `0xd9ba8633a96c91eea2c180e23e8cca8bb8cfd438764143d7ca4753c3e2b7f5fe`
  1. Increment the counter again.
  • Shared:
rooch move run --function 0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::increase --args object:0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter

Check:

[joe@mx quick_start_object_counter]$ rooch object --id 0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter
 
{
  "value": "0x5d6b1f08e259030c7493b7b4b0f78a390cf3eb81b720d5ef123a6f7ba794c3880000000000000000000000000000000000000000000000000000000000000000010100000000000000",
  "value_type": "0x2::object::ObjectEntity<0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter>",
  "decoded_value": {
    "abilities": 0,
    "type": "0x2::object::ObjectEntity<0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter>",
    "value": {
      "flag": 1,
      "id": "0x5d6b1f08e259030c7493b7b4b0f78a390cf3eb81b720d5ef123a6f7ba794c388",
      "owner": "0x0000000000000000000000000000000000000000000000000000000000000000",
      "value": {
        "abilities": 12,
        "type": "0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::Counter",
        "value": {
          "count_value": "2"    <= Note here!
        }
      }
    }
  }
}
  • User owns:
[joe@mx quick_start_object_counter]$ rooch move run --function 0x94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63::quick_start_object_counter::increase --args object:0x09dd7a2f60fda09c7e9009041b36742109911fe79b0240a0badc07fc800fc4c2
 
Transaction error: RPC call failed: ErrorObject { code: ServerError(-32000), message: "VMError with status NO_ACCOUNT_ROLE at location UNDEFINED and message Object owner mismatch, object owner:94bfa175058278af4afe25bb546f39bd4706d4c74539bbdc59c6d936b1695f63, sender:d9ba8633a96c91eea2c180e23e8cca8bb8cfd438764143d7ca4753c3e2b7f5fe", data: None }

As you can see, when we execute the increase function with another account, an error message will be returned, telling us that the owner of the object does not match, that is, other accounts cannot own objects owned by another account.

At this point, I believe you already have a certain understanding of Rooch's object storage. During the development process, you can reasonably use resource storage and object storage solutions according to your needs. In the simple_blog example, the two are combined.

Summarize

At this point you have learned step by step how to use Rooch to develop, deploy and call smart contracts. In Rooch, the object-oriented programming model is a very important content. To learn more about how to use it, please refer to Objects.