Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Onchain notes tutorial #604

Merged
merged 14 commits into from
Apr 26, 2024
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

## 0.3.0 (TBD)

## 0.2.1 (2024-04-12)

* [BREAKING] Return a reference to `NoteMetadata` from output notes (#593).
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions docs/introduction/get-started/p2p-private-offchain-txs.md
igamigo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ In this section, we show you how to make off-chain transactions and send funds t
To do this, run:

```shell
miden-client tx new p2id <regular-account-id-A> <regular-account-id-B> <faucet-account-id> 50
miden-client tx new p2id <regular-account-id-A> <regular-account-id-B> <faucet-account-id> 50 --note-type private
```

!!! note
Expand All @@ -55,7 +55,7 @@ In this section, we show you how to make off-chain transactions and send funds t
4. Have the second account consume the note.

```sh
miden-client tx new consume-notes <regular-account-ID-B> <input-note-id>
miden-client tx new consume-notes <regular-account-ID-B> <input-note-id>
```

!!! tip
Expand Down Expand Up @@ -97,4 +97,3 @@ You have successfully configured and used the Miden client to interact with a Mi
You have performed basic Miden rollup operations like sending transactions, generating and consuming notes.
igamigo marked this conversation as resolved.
Show resolved Hide resolved

For more information on the Miden client, refer to the [Miden client documentation](https://docs.polygon.technology/miden/miden-client/).

68 changes: 68 additions & 0 deletions docs/introduction/get-started/p2p-public-note-txs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
In this section, we show you how to execute transactions and send funds to another account using the Miden client through public notes.
igamigo marked this conversation as resolved.
Show resolved Hide resolved

!!! important "Prerequisite steps"
- You should have already followed all previous sections.
- You should have *not* reset the state of your local client.

## Create a second client

!!! tip
Remember to use the [Miden client documentation](https://docs.polygon.technology/miden/miden-client/cli-reference/) for clarifications.

This is an alternative to the private offchain P2P transactions article. For this tutorial, we will utilize two different clients to simulate two different remote users who don't share local state. To do this, we can have two terminals with their own state (using their own `miden-client.toml`). One terminal can run the client from the previous article, and a new terminal can run a new client.
igamigo marked this conversation as resolved.
Show resolved Hide resolved

1. On the new client, let's create a new basic account:
igamigo marked this conversation as resolved.
Show resolved Hide resolved

```shell
miden-client account new basic-immutable
igamigo marked this conversation as resolved.
Show resolved Hide resolved
```

2. List and view the accounts with the following command:
igamigo marked this conversation as resolved.
Show resolved Hide resolved

```shell
miden-client account -l
```

## Transfer assets between accounts

1. Now we can transfer some of the tokens we received from the faucet to our new account B.

To do this, from the first client run:

```shell
igamigo marked this conversation as resolved.
Show resolved Hide resolved
miden-client tx new p2id <regular-account-id-A> <regular-account-id-B> <faucet-account-id> 50 --note-type public
```

!!! note
Dominik1999 marked this conversation as resolved.
Show resolved Hide resolved
The faucet account id can be found on the [Miden faucet website](https://ethdenver.polygonmiden.io/) under the title **Miden faucet**.

This generates a Pay-to-ID (`P2ID`) note containing `<amount>` assets, transferred from one account to the other. As the note is public, the second account can receive the necessary details by syncing with the node.

2. First, sync the account on the new client.

```shell
miden-client sync # Make sure we have an updated view of the state
```

3. At this point, we should have received the public note details.

```sh
miden-client input-notes list
igamigo marked this conversation as resolved.
Show resolved Hide resolved
```

4. Have the second account consume the note.

```sh
miden-client tx new consume-notes <regular-account-ID-B> <input-note-id>
```

!!! tip
It's possible to use a short version of the note id: 7 characters after the `0x` is sufficient.

That's it!

The second account will have now consumed the note and should have new assets in the account:

```sh
miden-client account show <account-ID> -v
```
6 changes: 3 additions & 3 deletions miden-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "miden-lib"
version = "0.2.1"
version = "0.3.0"
description = "Standard library of the Miden rollup"
readme = "README.md"
categories = ["no-std"]
Expand Down Expand Up @@ -30,11 +30,11 @@ std = [
testing = ["miden-objects/testing"]

[dependencies]
miden-objects = { package = "miden-objects", path = "../objects", version = "0.2", default-features = false }
miden-objects = { package = "miden-objects", path = "../objects", version = "0.3", default-features = false }
miden-stdlib = { workspace = true }

[dev-dependencies]
miden-objects = { package = "miden-objects", path = "../objects", version = "0.2", default-features = false, features = [
miden-objects = { package = "miden-objects", path = "../objects", version = "0.3", default-features = false, features = [
"testing",
] }
mock = { package = "miden-mock", path = "../mock", default-features = false }
Expand Down
6 changes: 3 additions & 3 deletions miden-tx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "miden-tx"
version = "0.2.1"
version = "0.3.0"
description = "Miden rollup transaction compiler, executor, and prover"
readme = "README.md"
categories = ["no-std"]
Expand All @@ -22,8 +22,8 @@ default = ["std"]
std = ["miden-lib/std", "miden-objects/std", "miden-prover/std", "miden-verifier/std", "vm-processor/std"]

[dependencies]
miden-lib = { package = "miden-lib", path = "../miden-lib", version = "0.2", default-features = false }
miden-objects = { package = "miden-objects", path = "../objects", version = "0.2", default-features = false }
miden-lib = { package = "miden-lib", path = "../miden-lib", version = "0.3", default-features = false }
miden-objects = { package = "miden-objects", path = "../objects", version = "0.3", default-features = false }
miden-prover = { workspace = true }
miden-verifier = { workspace = true }
vm-processor = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions mock/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "miden-mock"
version = "0.2.0"
version = "0.3.0"
description = "Library for mocking and testing core Miden rollup components"
readme = "README.md"
keywords = ["miden", "mock"]
Expand Down Expand Up @@ -28,8 +28,8 @@ std = ["miden-lib/std", "miden-objects/std"]
clap = { version = "4.4", features = ["derive"], optional = true }
env_logger = { version = "0.11" }
hex = { version = "0.4" }
miden-lib = { path = "../miden-lib", version = "0.2" }
miden-objects = { path = "../objects", version = "0.2", features = [
miden-lib = { path = "../miden-lib", version = "0.3" }
miden-objects = { path = "../objects", version = "0.3", features = [
"log",
"serde",
"testing",
Expand Down
2 changes: 1 addition & 1 deletion objects/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "miden-objects"
version = "0.2.1"
version = "0.3.0"
description = "Core components of the Miden rollup"
readme = "README.md"
categories = ["no-std"]
Expand Down
Loading