Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions chapters/smart-contracts/lab/content/adder.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The Adder SC

The Adder smart contract is a simple smart contract with an `add` functionality and a global variable that can be incremented.
The Adder smart contract is a simple smart contract with an `add` functionality and a **global variable** that can be incremented.

```rust
/// One of the simplest smart contracts possible,
Expand Down Expand Up @@ -31,7 +31,7 @@ pub trait Adder {

We notice 4 functions:

* **sum** - this is a global variable, a `SingleValueMapper` (a single value) of type BigUint (unsigned integer);
* **sum** - this is a global variable, a `SingleValueMapper` (a single value) of type **BigUint** (unsigned integer);
* **init** - the constructor;
* **add** - function that increments the global variable (`sum`) with the `value` parameter;
* **upgrade** - function executed when upgrading the contract.
Expand All @@ -42,7 +42,7 @@ We notice 5 types of annotations:
* `#[storage_mapper("sum")]` - this is a global **variable** (also called a storage) stored at the contract address;
* `#[init]` - the constructor function; this is called when deploying the contract;
* `#[upgrade]` - this function is called when upgrading the contract;
* `#[endpoint]` - an endpoint is a function callable directly by the user; A function not having this annotation will not be exposed publicly.
* `#[endpoint]` - an endpoint is a function callable directly by the user; a function not having this annotation will not be exposed publicly.

[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.

Expand Down Expand Up @@ -177,7 +177,7 @@ Packing ../output/adder.mxsc.json ...
Contract size: 700 bytes.
```

Let's check the contract:
Let's check the `output` directory generated after running the build command:

```bash
ls -l output/
Expand Down
4 changes: 2 additions & 2 deletions chapters/smart-contracts/lab/content/empty.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ We have the annotation:
***
**NOTE**

Only **one** constructor is allowed per smart contract.
Only **one** constructor and **one** upgrade method are allowed per smart contract.
***

Let's build the smart contract, running the next command in the contract root:
Let's build the smart contract, running the next command in the **contract root**:

```sh
sc-meta all build
Expand Down
30 changes: 23 additions & 7 deletions chapters/smart-contracts/lab/content/empty_interaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ After building the contract, there are two main ways to interact with smart cont

## `mxpy` interaction

In the contract's root directory, you will create a file with a descriptive name. For instance, for out contract, which will be uploaded to Devnet, the file might be named: `devnet.snippets.sh`.
In the contract's **root directory**, you will create a file with a descriptive name. For instance, for out contract, which will be uploaded to Devnet, the file might be named: `devnet.snippets.sh`.

Once the contract is built, the WASM bytecode is generated in the `output/` directory, which we will utilize. This will be used within the newly created file:

Expand All @@ -25,6 +25,7 @@ deploySC() {
mxpy --verbose contract deploy \
--bytecode=${WASM_PATH} \
--pem=${WALLET_PEM} \
--gas-limit=2000000 \
--proxy=${PROXY} \
--send || return
}
Expand Down Expand Up @@ -70,7 +71,7 @@ Observe the output logs printed in the terminal. In the response JSON body, you

Rust interactors are used to interact with the blockchain via Rust.

Let's do this for the Empty smart contract. In the contract root run the next command:
Let's do this for the Empty smart contract. In the **contract root** run the next command:

```bash
sc-meta all snippets
Expand All @@ -94,24 +95,39 @@ A new folder `interactor` was created.

This will generate code for all the endpoints and view functions you created.

As this is a new and separate Rust binary, you must add it to the main `Cargo.toml`'s members:
As this is a new and separate Rust binary, you must **add** the interactor to the main `Cargo.toml`'s members, which is in the contract root, at path `empty/Cargo.toml`:

As this interactor is compiled as a new and separate Rust binary, you must add its path to the main `Cargo.toml`'s [workspace] members, located at the contract root, at path `empty/Cargo.toml`.

Before:

```toml
[workspace]
members = [
".",
"meta",
]
```

After:

```toml
[workspace]
members = [
".",
"meta",
"/home/empty/interactor"
"interactor"
]

```

Now, you can deploy your contract by running the following command in the `interactor directory.
Now, you can deploy your contract by running the following command in the `interactor` directory.

```bash
$ cargo run deploy
[...]
sender's recalled nonce: 10595
-- tx nonce: 10595
sender's recalled nonce: 19922
-- tx nonce: 19922
sc deploy tx hash: a17a4f51305b6f6dd9c01ec4986d0f90266ef560599b15af613e9aadd816e705
deploy address: erd1qqqqqqqqqqqqqpgqchszakc8fm44c2rndjh09xeuh829g4tgd8sskk0m5e
```
Expand Down