Skip to content

Commit

Permalink
feat: update to work with [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
chadoh committed Jul 5, 2022
1 parent 3c3be0e commit 4fa165a
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 34 deletions.
8 changes: 4 additions & 4 deletions src/counter/admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ Below View Methods, you'll see Change Methods.

![Change Calls](images/change.png)

Let's pick [`reset`](https://raen.dev/admin/#/counter.raendev.testnet/Reset).
Let's pick [`increment`](https://raen.dev/admin/#/counter.raendev.testnet/Increment).


![reset](images/reset.png)
![increment](images/increment.png)


Again you can see the comments from the code. However, now there are two new fields in the form.
Expand All @@ -39,11 +39,11 @@ Again you can see the comments from the code. However, now there are two new fie

You will need to sign in to submit this form. If you don't have a NEAR [testnet](https://docs.near.org/docs/concepts/networks#testnet) account, NEAR Wallet will guide you through creating one. Pro tip: select Email Recovery. It's plenty safe for testnet, and will greatly simplify recovering your account and using it in multiple browsers.

Once you sign in and submit the `reset` form, you can revisit [`get_num`](https://raen.dev/admin/#/counter.raendev.testnet/GetNum) and see that it is now `0` (unless someone else already changed it again).
Once you sign in and submit the `increment` form, you can revisit [`get_num`](https://raen.dev/admin/#/counter.raendev.testnet/GetNum) and see that it is now `0` (unless someone else already changed it again).

## Digging deeper: look, no NEAR Wallet confirmation

If you're used to Ethereum apps, you may be surprised that submitting the `reset` form didn't require any confirmation to spend your testnet NEAR tokens on transaction fees.
If you're used to Ethereum apps, you may be surprised that submitting the `increment` form didn't require any confirmation to spend your testnet NEAR tokens on transaction fees.

NEAR prioritizes both developer and user experience. One way it accomplishes good user experience: [negligible and predictable transaction fees](https://docs.near.org/docs/concepts/gas), also called _gas_ fees. And then, if gas fees are negligible for most transactions, why bother requiring user confirmation over and over and over?

Expand Down
7 changes: 3 additions & 4 deletions src/counter/final_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Let's take a look at the full contract and go over details we skipped at first.
## Imports from `near-sdk`

```rust,noplayground,ignore
{{#include ../../examples/contracts/rust-counter/contract/src/lib.rs:5:6}}
{{#include ../../examples/contracts/counter/src/lib.rs:5:6}}
```

### Borsh
Expand All @@ -23,7 +23,7 @@ This is the real magic of `near-sdk`. Like `log` it is a macro, but generates c
## Contract struct

```rust,noplayground,ignore
{{#include ../../examples/contracts/rust-counter/contract/src/lib.rs:8:12}}
{{#include ../../examples/contracts/counter/src/lib.rs:8:12}}
```

`near_bindgen` here means that the contract's state comes from this struct.
Expand Down Expand Up @@ -77,9 +77,8 @@ where

## Full implementation


```rust,noplayground,ignore
{{#include ../../examples/contracts/rust-counter/contract/src/lib.rs:14:42}}
{{#include ../../examples/contracts/counter/src/lib.rs:14:34}}
```

In Rust, you can use `//` for regular comments and `///` for [documentation comments](https://doc.rust-lang.org/stable/book/ch14-02-publishing-to-crates-io.html#making-useful-documentation-comments), which will automatically be turned into documentation by various tooling.
Expand Down
2 changes: 1 addition & 1 deletion src/counter/first_steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
First the contract's state, what will be written to storage, needs to be defined.

```rust,noplayground,ignore
{{#include ../../examples/contracts/rust-counter/contract/src/lib.rs:10:12}}
{{#include ../../examples/contracts/counter/src/lib.rs:10:12}}
```

### `struct`
Expand Down
Binary file modified src/counter/images/change.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/counter/images/increment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/counter/images/reset.png
Binary file not shown.
10 changes: 5 additions & 5 deletions src/counter/impl.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
To attach methods to a `struct` in Rust, use an `impl`. As a reminder, here's our struct from the last page:

```rust,noplayground,ignore
{{#include ../../examples/contracts/rust-counter/contract/src/lib.rs:10:12}}
{{#include ../../examples/contracts/counter/src/lib.rs:10:12}}
```

## A view method

Let's add a method to view the field `val`.

```rust,noplayground,ignore
{{#include ../../examples/contracts/rust-counter/contract/src/lib.rs:15}}
{{#include ../../examples/contracts/rust-counter/contract/src/lib.rs:17:19}}
{{#include ../../examples/contracts/counter/src/lib.rs:15}}
{{#include ../../examples/contracts/counter/src/lib.rs:17:19}}
...
}
```
Expand Down Expand Up @@ -40,10 +40,10 @@ This accesses the field `val`. You will also notice that there is no `return` st
Next let's see how to mutate or change `val`.

```rust,noplayground,ignore
{{#include ../../examples/contracts/rust-counter/contract/src/lib.rs:15}}
{{#include ../../examples/contracts/counter/src/lib.rs:15}}
...
{{#include ../../examples/contracts/rust-counter/contract/src/lib.rs:22:26}}
{{#include ../../examples/contracts/counter/src/lib.rs:22:26}}
...
}
Expand Down
14 changes: 1 addition & 13 deletions src/counter/working_with_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,12 @@ Now we can finally use RAEN to build our contract!

<!-- Add instructions for cloning the examples repo; -->

From within the `rust-contracts` directory use the build command:
From within the `counter` directory use the build command:

```bash
raen build --release
```

or with `npm` script:

```bash
yarn build
```

or

```bash
npm run build
```

This creates a new [Wasm](https://webassembly.org/) binary file in `./target/res/counter_contract.wasm`. This Wasm file has a [Custom Section](https://webassembly.github.io/spec/core/appendix/custom.html) that explains its interfaces in a way other tooling can use. And the best part: even with this extra information embedded in the Wasm binary, the final result still comes out smaller than contracts built without RAEN, thanks to smart compression. (If you're unaccustomed to considering server-side code size, it's time to start building a new habit. Blockchains are space-constrained, and you'll need to pay for [storage costs](https://docs.near.org/docs/concepts/storage-staking).)

## Deploying
Expand Down
4 changes: 2 additions & 2 deletions src/guide/first_steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The simplest example of this is a counter. A contract that can read, increment,
First the contract's state, what will be written to storage, needs to be defined.

```rust,noplayground,ignore
{{#include ../../examples/contracts/rust-counter/contract/src/lib.rs:10:12}}
{{#include ../../examples/contracts/counter/src/lib.rs:10:12}}
```

A struct in Rust defines a data structure with fields. You might have seen a class or an object in JS. Unlike other languages, the data structure has no methods attached to it, rather it just defines the shape.
Expand All @@ -24,5 +24,5 @@ This means once `val` is incremented to `127`, the next time it will wrap around
Rust does allow you to attach methods to the data. This is done with an implementation (`impl`). Let's add a method to return the field `val`.

```rust,noplayground,ignore
{{#include ../../examples/contracts/rust-counter/contract/src/lib.rs:15:18}}
{{#include ../../examples/contracts/counter/src/lib.rs:15:18}}
```
6 changes: 3 additions & 3 deletions src/intro/getting-set-up.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
6. Clone the Examples repository:

```bash
git clone --depth 1 --branch v0.0.3 https://github.com/raendev/examples.git --recursive raen-examples
git clone --depth 1 --branch v0.0.4 https://github.com/raendev/examples.git --recursive raen-examples
```

This will clone [github.com/raendev/examples](https://github.com/raendev/examples) to a folder called `raen-examples`.

7. Build with RAEN.

Change into `raen-examples/contracts/rust-counter`, then build:
Change into `raen-examples/contracts/counter`, then build:

```bash
raen build --release
Expand All @@ -65,4 +65,4 @@

8. Open an example.

We're going to start with `raen-examples/contracts/rust-counter`. Open this folder in your editor. Let's take a look around.
We're going to start with `raen-examples/contracts/counter`. Open this folder in your editor. Let's take a look around.
4 changes: 2 additions & 2 deletions src/status-message/set_message.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@


```rust,noplayground,ignore
{{#include ../../examples/contracts/rust-counter/contract/src/lib.rs}}
```
{{#include ../../examples/contracts/counter/src/lib.rs}}
```

0 comments on commit 4fa165a

Please sign in to comment.