Skip to content

Conversation

@anataliocs
Copy link
Contributor

@anataliocs anataliocs commented Dec 3, 2025

Related Issue:
fixes #545

Title:

Writing Your First Smart Contract

Description:

Walk through hand-on instructions to create a
fully functional ink! smart contract.

Attached companion GitHub template repo helloink.

Explain key concepts:

  • Using the Pop CLI
  • Storage: Reading, Writing & Mutating Storage
  • Constructors
  • Messages
  • Ink contract macros

Learning Objectives:

  • By the end of this tutorial, you will be able to write, build, test and deploy ink! contracts
  • You will be familiar with all the key components of an ink! smart contract
  • You will understand how to use the Pop CLI
  • You will understand important concepts like storage, events and how to use them in your smart contract

Local Testing Steps

Copy link
Contributor

@Daanvdplas Daanvdplas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Thank you very much for your contribution!

One comment I have: once a link is added in text I would like it to make things more clear. now the links often reference official rust docs but I'm not always of the opinion that is beginner friendly. As an alternative, some links can be added at the end of a section for optional further reading, this to keep the flow of the actual section light and easy.

I left some other small comments for you take a look at but other than that it looks good to go!


There are two ways to follow along with this tutorial!

### GitHub Codespace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a little difficult for beginners?

Comment on lines +59 to +61
- Install [Brew](https://brew.sh/)
- Install [Rust](https://rust-lang.org/tools/install/), [Cargo](https://doc.rust-lang.org/cargo/)
and [Pop CLI](https://github.com/r0gue-io/pop-cli)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All those steps are included here: https://learn.onpop.io/contracts/welcome/install-pop-cli

We should make it easier to install pop-cli

Read up on the [Pop CLI](https://learn.onpop.io/)
:::

### Verify Installation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just verify pop

- Pass in `contract` to the command `pop new`
- We name the contract`helloink`
- Lastly, we use the [Standard Template](https://github.com/use-ink/ink-examples/tree/main/flipper),
passing in `-t standard`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed if we use the interactive mode

Suggested change
passing in `-t standard`

Comment on lines +120 to +122
```bash
pop new contract helloink -t standard
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the full command if they don't want interactive mode, maybe we should make that clear.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw there is also a question whether they want a frontend or not now, we should specify that they can click no

_Let's review each major component of the `lib.rs` file:_

### Conditional Compilation Statement

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```rust
#![cfg_attr(not(feature = "std"), no_std, no_main)]

Comment on lines +169 to +173
**lib.rs** (excerpt)

```rust
#![cfg_attr(not(feature = "std"), no_std, no_main)]
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**lib.rs** (excerpt)
```rust
#![cfg_attr(not(feature = "std"), no_std, no_main)]
```

Applies the `#[ink(constructor)]` macro to the `new()` function declaration.

- Marks the function as the **ink!** constructor
- Makes function available to the API for instantiating the contract
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps explain what instantiating is?

## Deploy to Local Ink Node

Now, let's use [Pop to deploy our contract](https://learn.onpop.io/contracts/guides/deploy) to
a [local ink node](https://github.com/use-ink/ink-node).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much info:

Suggested change
a [local ink node](https://github.com/use-ink/ink-node).
a local ink node.

Comment on lines +385 to +397
- `--path` points to the contract directory
- `--constructor` method name (defaults to `new`)
- `--args` constructor arguments
- `--suri` secret key URI (default to `//Alice`)
- `--url` ink node url (default `ws://localhost:9944`)

```bash
pop up --path . \
--constructor new \
--args true \
--suri //Alice \
--url ws://localhost:9944
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just run pop up -w which uses a wallet integration, or pop up --suri //Alice

Point I'm trying to make, let them discover pop interactive mode :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add tutorial for - Writing Your First Smart Contract

2 participants