Skip to content

Commit 278ef7f

Browse files
Merge pull request #70 from cs-pub-ro/update-sc
update SC
2 parents 52d58d7 + e4cd8ee commit 278ef7f

File tree

11 files changed

+724
-390
lines changed

11 files changed

+724
-390
lines changed

chapters/smart-contracts/lab/content/adder.md

Lines changed: 123 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,80 +30,165 @@ pub trait Adder {
3030
```
3131

3232
We notice 4 functions:
33+
3334
* **sum** - this is a global variable, a `SingleValueMapper` (a single value) of type BigUint (unsigned integer);
3435
* **init** - the constructor;
3536
* **add** - function that increments the global variable (`sum`) with the `value` parameter;
3637
* **upgrade** - function executed when upgrading the contract.
3738

3839
We notice 5 types of annotations:
40+
3941
* `#[view(getSum)]` - this is a function that allows you to read the storage variable by calling the function `getSum`;
4042
* `#[storage_mapper("sum")]` - this is a global **variable** (also called a storage) stored at the contract address;
4143
* `#[init]` - the constructor function; this is called when deploying the contract;
4244
* `#[upgrade]` - this function is called when upgrading the contract;
4345
* `#[endpoint]` - an endpoint is a function callable directly by the user; A function not having this annotation will not be exposed publicly.
4446

47+
[Here](https://github.com/multiversx/mx-contracts-rs/blob/main/contracts/adder/src/adder.rs) is the smart contract code listed above and [here](https://github.com/multiversx/mx-contracts-rs/tree/main/contracts/adder) are all the files needed for compilation.
4548

46-
[Here](https://github.com/multiversx/mx-contracts-rs/blob/main/contracts/adder/src/adder.rs) is the smart contract code listed above and [here](https://github.com/multiversx/mx-contracts-rs/tree/main/contracts/adder) are all the files needed for compilation.
49+
You can obtain the adder smart contract code directly using the following command:
4750

51+
```bash
52+
sc-meta new --template adder
53+
```
54+
55+
Let's build the smart contract, running the next command in the contract root:
56+
57+
```sh
58+
sc-meta all build
59+
```
4860

49-
Let's compile the contract:
61+
Below, it is the output of the command:
5062

5163
```bash
52-
costin@Byblos:~/mvx/mx-contracts-rs/contracts/adder$ sc-meta all build
53-
/home/costin/mvx/mx-contracts-rs/contracts/adder
64+
/home/adder
5465

5566
Found 1 contract crates.
5667

5768
(1/1)
58-
In /home/costin/mvx/mx-contracts-rs/contracts/adder/meta
69+
In /home/adder/meta
5970
Calling `cargo run build`
60-
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
61-
Running `/home/costin/mvx/mx-contracts-rs/target/debug/adder-meta build`
62-
Using workspace target directory: /home/costin/mvx/mx-contracts-rs/target ...
63-
Building adder.wasm in /home/costin/mvx/mx-contracts-rs/contracts/adder/wasm ...
64-
RUSTFLAGS="-C link-arg=-s -C link-arg=-zstack-size=131072" cargo build --target=wasm32-unknown-unknown --release --target-dir /home/costin/mvx/mx-contracts-rs/target
65-
Compiling proc-macro2 v1.0.86
66-
Compiling unicode-ident v1.0.13
67-
Compiling smallvec v1.13.2
68-
Compiling autocfg v1.4.0
71+
Compiling syn v2.0.110
72+
Compiling serde_core v1.0.228
73+
Compiling num-traits v0.2.19
74+
Compiling bitflags v2.10.0
6975
Compiling hex v0.4.3
70-
Compiling endian-type v0.1.2
76+
Compiling equivalent v1.0.2
77+
Compiling utf8parse v0.2.2
78+
Compiling unwrap-infallible v0.1.5
79+
Compiling hashbrown v0.16.0
7180
Compiling arrayvec v0.7.6
81+
Compiling typenum v1.19.0
82+
Compiling semver v1.0.27
83+
Compiling anstyle-query v1.1.4
84+
Compiling memchr v2.7.6
85+
Compiling anstyle-parse v0.2.7
86+
Compiling colorchoice v1.0.4
87+
Compiling is_terminal_polyfill v1.70.2
88+
Compiling leb128fmt v0.1.0
89+
Compiling foldhash v0.1.5
90+
Compiling anstyle v1.0.13
91+
Compiling unicode-width v0.2.2
92+
Compiling serde_json v1.0.145
93+
Compiling wasm-encoder v0.240.0
94+
Compiling winnow v0.7.13
95+
Compiling hex-literal v1.1.0
96+
Compiling anstream v0.6.21
97+
Compiling strsim v0.11.1
98+
Compiling bumpalo v3.19.0
99+
Compiling clap_lex v0.7.6
100+
Compiling anyhow v1.0.100
101+
Compiling ryu v1.0.20
102+
Compiling clap_builder v4.5.51
103+
Compiling toml_writer v1.0.4
104+
Compiling generic-array v1.3.5
105+
Compiling itoa v1.0.15
106+
Compiling unicode-segmentation v1.12.0
107+
Compiling termcolor v1.4.1
108+
Compiling rustc_version v0.4.1
109+
Compiling lazy_static v1.5.0
110+
Compiling colored v3.0.0
111+
Compiling num-integer v0.1.46
112+
Compiling convert_case v0.8.0
113+
Compiling num-bigint v0.4.6
114+
Compiling wast v240.0.0
115+
Compiling toml_parser v1.0.4
116+
Compiling indexmap v2.12.0
117+
Compiling serde_spanned v1.0.3
118+
Compiling toml_datetime v0.7.3
119+
Compiling toml v0.9.8
120+
Compiling multiversx-sc-codec-derive v0.23.1
121+
Compiling serde_derive v1.0.228
122+
Compiling multiversx-sc-derive v0.62.1
123+
Compiling clap_derive v4.5.49
124+
Compiling multiversx-sc-codec v0.23.1
125+
Compiling clap v4.5.51
126+
Compiling multiversx-chain-core v0.19.1
127+
Compiling multiversx-sc v0.62.1
128+
Compiling serde v1.0.228
129+
Compiling hashbrown v0.15.5
130+
Compiling wat v1.240.0
131+
Compiling wasmparser v0.239.0
132+
Compiling adder v0.0.0 (/home/adder)
133+
Compiling wasmprinter v0.239.0
134+
Compiling multiversx-sc-meta-lib v0.62.1
135+
Compiling adder-meta v0.0.0 (/home/adder/meta)
136+
Finished `dev` profile [unoptimized + debuginfo] target(s) in 13.82s
137+
Running `/home/adder/target/debug/adder-meta build`
138+
Using workspace target directory: /home/adder/target ...
139+
Building adder.wasm in /home/adder/wasm ...
140+
RUSTFLAGS="-C link-arg=-s -C link-arg=-zstack-size=131072" cargo build --target=wasm32v1-none --release --target-dir /home/adder/target
141+
Updating crates.io index
142+
Blocking waiting for file lock on package cache
143+
Locking 25 packages to latest compatible versions
144+
Blocking waiting for file lock on package cache
145+
Compiling proc-macro2 v1.0.103
146+
Compiling unicode-ident v1.0.22
147+
Compiling quote v1.0.42
148+
Compiling hex v0.4.3
149+
Compiling smallvec v1.15.1
150+
Compiling typenum v1.19.0
151+
Compiling rustversion v1.0.22
152+
Compiling autocfg v1.5.0
153+
Compiling bitflags v2.10.0
154+
Compiling endian-type v0.2.0
72155
Compiling unwrap-infallible v0.1.5
73-
Compiling bitflags v2.6.0
74-
Compiling hex-literal v0.4.1
75-
Compiling nibble_vec v0.1.0
76-
Compiling radix_trie v0.2.1
156+
Compiling arrayvec v0.7.6
157+
Compiling hex-literal v1.1.0
77158
Compiling num-traits v0.2.19
78-
Compiling quote v1.0.37
79-
Compiling syn v2.0.77
80-
Compiling multiversx-sc-codec-derive v0.21.0
81-
Compiling multiversx-sc-derive v0.53.2
82-
Compiling multiversx-sc-codec v0.21.0
83-
Compiling multiversx-sc v0.53.2
84-
Compiling adder v0.0.0 (/home/costin/mvx/mx-contracts-rs/contracts/adder)
85-
Compiling multiversx-sc-wasm-adapter v0.53.2
86-
Compiling adder-wasm v0.0.0 (/home/costin/mvx/mx-contracts-rs/contracts/adder/wasm)
87-
Finished `release` profile [optimized] target(s) in 8.69s
88-
Copying /home/costin/mvx/mx-contracts-rs/target/wasm32-unknown-unknown/release/adder_wasm.wasm to ../output/adder.wasm ...
159+
Compiling nibble_vec v0.1.0
160+
Compiling radix_trie v0.3.0
161+
Compiling syn v2.0.110
162+
Compiling generic-array v1.3.5
163+
Compiling multiversx-sc-codec-derive v0.23.1
164+
Compiling multiversx-sc-derive v0.62.1
165+
Compiling multiversx-sc-codec v0.23.1
166+
Compiling multiversx-chain-core v0.19.1
167+
Compiling multiversx-sc v0.62.1
168+
Compiling adder v0.0.0 (/home/adder)
169+
Compiling multiversx-sc-wasm-adapter v0.62.1
170+
Compiling adder-wasm v0.0.0 (/home/adder/wasm)
171+
Finished `release` profile [optimized] target(s) in 8.55s
172+
Copying /home/adder/target/wasm32v1-none/release/adder_wasm.wasm to ../output/adder.wasm ...
89173
Calling wasm-opt on ../output/adder.wasm ...
90174
Extracting imports to ../output/adder.imports.json ...
91-
Checking EI version: 1.3 ... OK
175+
Checking EI version: 1.5 ... OK
92176
Packing ../output/adder.mxsc.json ...
93-
Contract size: 696 bytes.
177+
Contract size: 700 bytes.
94178
```
95179

96180
Let's check the contract:
181+
97182
```bash
98-
costin@Byblos:~/mvx/mx-contracts-rs/contracts/adder$ ls -l output/
183+
ls -l output/
99184
total 16
100-
-rw-rw-r-- 1 costin costin 1792 nov 7 13:28 adder.abi.json
101-
-rw-rw-r-- 1 costin costin 262 nov 7 13:28 adder.imports.json
102-
-rw-rw-r-- 1 costin costin 4070 nov 7 13:28 adder.mxsc.json
103-
-rwxrwxr-x 1 costin costin 696 nov 7 13:28 adder.wasm
185+
-rw-rw-r-- 1 user user 1727 nov 13 15:09 adder.abi.json
186+
-rw-rw-r-- 1 user user 262 nov 13 15:09 adder.imports.json
187+
-rw-rw-r-- 1 user user 4078 nov 13 15:09 adder.mxsc.json
188+
-rwxrwxr-x 1 user user 700 nov 13 15:09 adder.wasm
104189
```
105190

106-
We notice that the resulted contract (`adder.wasm`) has 696 bytes.
191+
We notice that the resulted contract (`adder.wasm`) has 700 bytes.
107192

108193
## Practice
109194

0 commit comments

Comments
 (0)