Dive into Move on Sui
Sui
Agenda
Introduction
Writing Contracts with Move
Quick Tips
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 ?
An Infrastructure for Gaming and more
SuiPlay0X1
Programmable Storage
How to use Sui?
Move
Expressive by nature
Intuitive by design
Secure by default
Move
Let's Move on
Warranty Card
信君 劉's photo, licensed as CC BY-SA 2.0
Expiry date
Serial number
Stamp from issuer
Repairing records
Gororo Warranty
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 own this brand
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
Ownership
&T : Read
T: Consume
&mut T: Write
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
git clone https://github.com/yanganto/BobaCoupon
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
Functions
Init fun
public entry fun
public fun
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 do it now
POC quick with Template
Open PR & Use CI
Customized Sui for CI
Run test in sendbox
Ideal first, No wallet
Show test coverage
Tic-tac-toe
Tic-tac-toe
https://github.com/yanganto/Tic-tac-toe
Quick Tips When Build
Quick Tips When Build
Test and build locally
sui move new
sui move build
sui move test
curl --proto '=https' --tlsv1.2 -sSf \
https://sh.rustup.rs | sh
git clone https://github.com/MystenLabs/sui
cargo build
Binary in ./target/debug/sui
Install Rust & Build or Download binary
cargo build
Download from https://github.com/MystenLabs/sui/releases
How to stet up Display
Where is package ID
sui client publish
Move.lock
STDOUT
Thank you
Q & A
Materials
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
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
Move
Move
Option<T>
T
u64
()
There is no Result, Future in Move, and we handle error as u64
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
let's Move on
Move
CEO from
Evan Cheng
Gororo Warranty
lord enfield's photo, licensed as CC BY 2.0
let's Move on
Move
It's your turn
Repairing Service
User comment and repairing ranking
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