Skip to content

Commit

Permalink
feat: upgrade flipper to ink!4 (#284)
Browse files Browse the repository at this point in the history
* feat: upgrade flipper to ink!4

* Update docs/build/wasm/from-zero-to-ink-hero/flipper-contract/flipper.md

* Update docs/build/wasm/from-zero-to-ink-hero/flipper-contract/flipper.md

---------

Co-authored-by: midegdugarova <59020389+midegdugarova@users.noreply.github.com>
  • Loading branch information
ashutoshvarma and midegdugarova committed Mar 21, 2023
1 parent 43b518e commit c981a53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ This tutorial targets developers with no experience in ink! and a **basic** leve
- Basic Rust knowledge. [Learn Rust](https://www.rust-lang.org/learn).

### What will we do?
In this tutorial we will implement the most basic contract: [Flipper](https://github.com/paritytech/ink/blob/v3.3.0/examples/flipper/lib.rs) in ink!.
In this tutorial we will implement the most basic contract: [Flipper](https://github.com/paritytech/ink/blob/v4.0.0/examples/flipper/lib.rs) in ink!.

### What will we use?
- [ink! 3.3.0](https://github.com/paritytech/ink/tree/v3.3.0)
- [ink! 4.0.0](https://github.com/paritytech/ink/tree/v4.0.0)

### What will you learn?
- Anatomy of an ink! contract
Expand Down
32 changes: 15 additions & 17 deletions docs/build/wasm/from-zero-to-ink-hero/flipper-contract/flipper.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,14 @@ Let’s dive a bit deeper into the project structure:
```rust
#![cfg_attr(not(feature = "std"), no_std)]

use ink_lang as ink;

#[ink::contract]
mod flipper {

/// Defines the storage of your contract.
/// Add new fields to the below struct in order
/// to add new static storage fields to your contract.
#[ink(storage)]
pub struct Flipper {
pub struct Flipper {
/// Stores a single `bool` value on the storage.
value: bool,
}
Expand Down Expand Up @@ -104,9 +102,6 @@ mod flipper {
/// Imports all the definitions from the outer scope so we can use them here.
use super::*;

/// Imports `ink_lang` so we can use `#[ink::test]`.
use ink_lang as ink;

/// We test if the default constructor does its job.
#[ink::test]
fn default_works() {
Expand Down Expand Up @@ -162,23 +157,25 @@ mod flipper {
```

This annotates a struct that represents the **contract's internal state.** ([details](https://use.ink/macros-attributes/storage)):

```rust
#[ink(storage)]
```

Storage types:

- Rust primitives types
- `bool`
- `u{8,16,32,64,128}`
- `i{8,16,32,64,128}`
- `String`
- `bool`
- `u{8,16,32,64,128}`
- `i{8,16,32,64,128}`
- `String`
- Substrate specific types
- `AccountId`
- `Balance`
- `Hash`
- `AccountId`
- `Balance`
- `Hash`
- ink! storage type
- `Mapping`
- Custom data Structure [details](https://use.ink/datastructures/custom-datastructure)
- `Mapping`
- Custom data structure [details](https://use.ink/datastructures/custom-datastructure)

This means the contract (Flipper) stores a single `bool` value in storage.

Expand Down Expand Up @@ -214,7 +211,7 @@ pub fn default() -> Self {
}
```

The following will permit a function to be **publicly dispatchable**, meaning that it will be exposed in the contract interface to the outside world. [For more information](https://use.ink/4.0.0-alpha.1/macros-attributes/message)). Note that all public functions **must** use the `#[ink(message)]` attribute.
The following will permit a function to be **publicly dispatchable**, meaning that the function can be called through a message, which is a way for contracts and external accounts to interact with the contract. Find more information [here](https://use.ink/macros-attributes/message)). Note that all public functions **must** use the `#[ink(message)]` attribute.

```rust
#[ink(message)]
Expand All @@ -238,7 +235,7 @@ pub fn get(&self) -> bool {

```rust
impl Flipper {

#[ink(constructor)]
pub fn new(init_value: bool) -> Self {
Self { value: init_value }
Expand Down Expand Up @@ -299,5 +296,6 @@ impl Flipper {

### Compile, Deploy and Interact with Contracts


Follow this guide to deploy your contract [using Polkadot UI](https://docs.astar.network/docs/build/wasm/tooling/polkadotjs/). Once deployed, you will be able to interact with it.

0 comments on commit c981a53

Please sign in to comment.