Dive into Move on Sui
Sui
Agenda
Introduction
Writing contracts with Move
Quick guide for Rust dev
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11806096/SlideQR.png)
Web Evolution
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11799926/5806709797_0c338a4a2a_w.jpg)
"Human Evolution" by acidpix is licensed under CC BY 2.0 .
Digitals
To Read
To Write
To Own
Owner's manual
![](https://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Ford_manual_1919.djvu/page1-800px-Ford_manual_1919.djvu.jpg)
https://en.wikipedia.org/wiki/Owner%27s_manual
public domain image
Owner's manual
https://support.apple.com/en-asia/guide/iphone/welcome/ios
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11799901/iPhone.png)
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
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11799961/24780912833_92fd8226a5_w.jpg)
信君 劉's photo, licensed as CC BY-SA 2.0
-
Expiry date
-
Serial number
-
Stamp from issuer
-
Repairing records
Gororo Warranty
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11800995/gororo.jpg)
lord enfield's photo, licensed as CC BY 2.0
Structs
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11803094/warranty_struct.png)
The global object knows who has owner's cap
The only cap for admin
The warranty cards
The records for reparing
Init Function
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11803094/warranty_struct.png)
The global object knows who has owner's cap
The only cap for admin
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11803126/warranty_init.png)
The init exec only once when contract deploy
The share_object let the instance global
Entry Functions
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11803301/issue_warranty.png)
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
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11803315/stest_warranty.png)
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
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11803315/stest_warranty.png)
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
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11803315/stest_warranty.png)
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
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11807888/boba.jpg)
Move.toml
Leverage other open source project on Sui
to build your campaign
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11804389/Coupon_meta.png)
Structs
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11804566/CouponCode.png)
A global object to know who claim the coupon, and which one isused
The coupons
Public Functions
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11804566/CouponCode.png)
reply on Card in gororo package
Use public function in_repairing from gororo package
Scenario Test
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11804784/coupon_test.png)
Setup warranty to Alice for test
The init from gororo
The init from boba
Scenario Test
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11807537/Test1.png)
claim coupon
redeem it
Scenario Test
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11804829/expect_failure.png)
Expect the scenario will fail with specific error code
Scenario Test
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11807584/Test2.png)
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
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11804417/repair.jpg)
Use Template
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11804910/Template_repo.png)
Open PR & Use CI
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11804918/CI.png)
-
Customized Sui for CI
-
Run test in sendbox
-
Ideal first, No wallet
-
Show test coverage
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11804932/TestCoverage.png)
From to Move
Move
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7088226/1024px-Rust_programming_language_black_logo.svg.png)
Quick Tips
use test_with::env;
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7088226/1024px-Rust_programming_language_black_logo.svg.png)
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 }
}
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7088226/1024px-Rust_programming_language_black_logo.svg.png)
Move
Move
Impl some functionality for a type.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11806084/MethodAliases.png)
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
}
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7088226/1024px-Rust_programming_language_black_logo.svg.png)
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!
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7088226/1024px-Rust_programming_language_black_logo.svg.png)
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
- ()
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7088226/1024px-Rust_programming_language_black_logo.svg.png)
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
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7088226/1024px-Rust_programming_language_black_logo.svg.png)
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
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/11807862/SuiLoveTW.jpg)
Materials
Dive Into Move on Sui
By Antonio Yang
Dive Into Move on Sui
- 43