Dive into Move on Sui

Antonio Yang - yanganto@github

Sui Foundation - Developer Relations

 

Sui

Agenda

Introduction
Writing contracts with Move

Quick guide for Rust dev

Web Evolution

"Human Evolution" by acidpix is licensed under CC BY 2.0 .

Digitals

To Read

To Write

To Own

Owner's manual

https://en.wikipedia.org/wiki/Owner%27s_manual

public domain image

Owner's manual

https://support.apple.com/en-asia/guide/iphone/welcome/ios

To Own
Should be easy

 

Object Model
32-byte global UID

8-byte version

32-byte tx digest

32-byte owner

https://docs.sui.io/concepts/object-model#object-metadata

Sui

Who is Sui ?

TW

&

CEO from

TW

Evan Cheng

SuiPlay0X1

How to use Sui?

Move

Expressive by nature
Intuitive by design

Secure by default

For the things we have to learn before we can do them, we learn by doing them.

- Aristotle

let's Move on

Move

Warranty Card

信君 劉's photo, licensed as CC BY-SA 2.0

  • Expiry date

  • Serial number

  • Stamp from issuer

  • Repairing records

Gororo Warranty

lord enfield's photo, licensed as CC BY 2.0

Structs

The global object knows who has owner's cap

The only cap for admin

The warranty cards

The records for reparing

Init Function

The global object knows  who has  owner's cap

The only cap for admin

The init exec only once when contract deploy

The share_object let the instance global

Entry Functions

 The global object

The cap for admin only

entry functions can be called from the package on Sui

Use cap to do access control

Scenario Test

Set up accounts will use in the test

The admin begin the test, so he will have cap in the scenario

The init with scenario context

Scenario test

Use take_shared to get the global object

Use take_from_sender to get the object from the caller

Use return_shared and return_to_sender to return objecs

Scenario Test

The first buyer sells the gororo to the second buyer and transfers the warranty card to him

The lamp of gororo is broken, so second buyer puts the bike to shop and send warranty card to technician

The lamp of gororo is repaired, so technician add repairing record and send warranty card back

debug::print to check

let's Move on

Move

Coupon

  • Special discount

  • Claim in the web

  • Leveraging the power of Sui

Boba Coupon

Move.toml

Leverage other open source project on Sui
to build your campaign

Structs

A global object to know who claim the coupon, and which one isused

The coupons

Public Functions

reply on Card in gororo package

Use public function in_repairing from gororo package

Scenario Test

Setup warranty to Alice for test

The init from gororo

The init from boba

Scenario Test

claim coupon

redeem it

Scenario Test

Expect the scenario will fail with specific error code

Scenario Test

Expect error because technician is not a real owner

let's Move on

Move

TW

It's your turn

Repairing Shop

  • Repairing

  • Rely on Gororo warranty

  • Check warranty do different service

  • Auto claim the boba coupon before user in repairing

Tim Vrtiska's photo, licensed as CC BY-ND 2.0

Use Template

Open PR & Use CI

  • Customized Sui for CI

  • Run test in sendbox

  • Ideal first, No wallet

  • Show test coverage

From              to Move

Move

Quick Tips

use test_with::env;

use std::net::TcpStream;

use std::net;

use sui::vec_sec::VecSec;

use sui::vec_sec::singleton;

use 0x2::vec_set;

Move

Move

use Crate::{module, fn, struct, trait, macro fn}...

use Package::module::{fun, struct}

Always the same layering namespace

Package is an address, alias set in Move.toml

struct Example {number: i32}

impl Example {
    fn boo() { println!("boo! Example::boo() was called!"); }

    fn answer(&mut self) { self.number += 42; }

    fn get_number(&self) -> i32 { self.number }
}

Move

Move

Impl some functionality for a type.

Method Aliases

trait Animal {
    fn new(name: &'static str) -> Self;
    fn name(&self) -> &'static str;
    fn talk(&self) { println!("{} says {}", self.name(), self.noise());}
    fn eat(&mut self);
}

impl Animal for Sheep {

    ... // fn can be overwritten

}

Move

Move

Traits a collection of methods defined for an unknown type

4 abilities - copy, drop, key, store 

Ability define how types behave

Drop is optional

  • fn
  • public fn
  • async fn
  • unsafe fn
  • macro!

Move

Move

fun

init fun

entry fun

public  fun

macro fun

There is no async, unsafe in Move, and we need focus on when and who to call the function

  • Result<T, E>
  • Option<T>
  • Future<Output=T>
  • T  
  • ()

Move

Move

Option<T>

T

u64

() 

There is no Result, Future in Move, and we handle error as u64

  • cargo new
  • cargo build
  • cargo test
  • cargo publish

Move

Move

Storage package on chain coats Sui,

so a wallet need to setup before publish 

sui move new

sui move build

sui move test

sui client publish

TW

Thank you

Q & A

Materials