1 module Hello {
2 use 0x1::Signer;
3 use 0x1::Event;
4
5 struct AnyWordEvent has drop, store {
6 words: vector,
7 }
8
9 struct EventHolder has key {
10 any_word_events: Event::EventHandle,
11 }
12
13 public(script) fun hello(account: signer) acquires EventHolder {
14 let _account = &account;
15 let addr = Signer::address_of(_account);
16 if (!exists(copy addr)){
17 move_to(_account, EventHolder {
18 any_word_events: Event::new_event_handle(_account),
19 });
20 };
21 let hello_world = x"68656c6c6f20776f726c64";//hello world
22 let holder = borrow_global_mut(addr);
23 Event::emit_event(&mut holder.any_word_events, AnyWordEvent { words:hello_world });
24 }
25 }
1 module MyToken {
2 use 0x1::Token;
3 use 0x1::Account;
4
5 struct MyToken has copy, drop, store { }
6
7 public(script) fun init(account: signer) {
8 let _account = &account;
9 Token::register_token(_account, 3);
10 Account::do_accept_token(_account);
11 }
12
13 public(script) fun mint(account: signer, amount: u128) {
14 let _account = &account;
15 let token = Token::mint(_account, amount);
16 Account::deposit_to_self(_account, token)
17 }
18 }
1 module NFTExample {
2 use 0x1::Signer;
3 struct NFT has key, store { name: vector }
4
5 struct UniqIdList has key, store {
6 data: vector>
7 }
8 public fun initialize(account: &signer) {
9 move_to(account, UniqIdList {data: Vector::empty>()});
10 }
11 public fun new(account: &signer, name: vector): NFT acquires UniqIdList {
12 let account_address = Signer::address_of(account);
13 let exist = Vector::contains>(&borrow_global(account_address).data, &name);
14 assert(!exist, 1);
15 let id_list = borrow_global_mut(account_address);
16 Vector::push_back>(&mut id_list.data, copy name);
17 NFT { name }
18 }
19 public fun destroy(account_address: address, nft: NFT) acquires UniqIdList {
20 let NFT { name } = nft;
21 let (exist, index) = Vector::index_of>(&borrow_global(account_address).data, &name);
22 assert(!exist, 2);
23 let id_list = borrow_global_mut(account_address);
24 Vector::remove>(&mut id_list.data, index);
25 }
26 }
1 module ResourceExample {
2 use 0x1::Signer;
3
4 struct R has key, store { x: bool }
5
6 public fun new(): R {
7 R { x: true }
8 }
9
10 public fun destroy(r: R) {
11 R { x: _ } = r;
12 }
13
14 public fun save(account: &signer, r: R){
15 move_to(account, r);
16 }
17
18 public fun get_x(account: &signer): bool acquires R {
19 let sender = Signer::address_of(account);
20 assert(exists(sender), 1);
21 let r = borrow_global(sender);
22 r.x
23 }
24 }
1 script {
2 use 0x1::Dao;
3 use {{coder}}::MyToken::MyToken;
4 use 0x1::Config;
5
6 fun set_dao_config(signer: signer) {
7 let cap = Config::extract_modify_config_capability>(
8 &signer
9 );
10
11 Dao::set_voting_delay(&mut cap, 30 * 1000);
12 Dao::set_voting_period(&mut cap, 30 * 30 * 1000);
13 Dao::set_voting_quorum_rate(&mut cap, 50);
14 Dao::set_min_action_delay(&mut cap, 30 * 30 * 1000);
15
16 Config::restore_modify_config_capability(cap);
17 }
18 }