Skip to content

Commit

Permalink
doc: update tutorial for latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
obycode committed Mar 16, 2023
1 parent ca1d9c0 commit f857186
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stacks-subnets"
version = "0.0.1"
version = "0.4.0"
authors = [
"Jude Nelson <jude@stacks.org>",
"Aaron Blankstein <aaron@hiro.so>",
Expand Down
4 changes: 2 additions & 2 deletions core-contracts/contracts/helper/subnet-traits.clar
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;; In order to process deposits and withdrawals to a subnet, an asset
;; contract must implement this trait.
;; In order to support withdrawing an asset that was minted on a subnet, the
;; L1 contract must implement this trait.
(define-trait mint-from-subnet-trait
(
;; Process a withdrawal from the subnet for an asset which does not yet
Expand Down
60 changes: 36 additions & 24 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ title: Getting Started
# Getting Started

Developers can test their applications on a subnet either locally, or on Hiro's
hosted testnet subnet. This page describes two different walkthroughs that illustrate how to use a subnet.
hosted testnet subnet. This page describes two different walkthroughs that
illustrate how to use a subnet.

- Run a local subnet
- Use Hiro's subnet on testnet

> **_NOTE:_**
>
> A subnet was previously referred to as a hyperchain. While the process of updating
> the content is ongoing, there may still be some references to a hyperchain
> instead of a subnet.
> A subnet was previously referred to as a hyperchain. While the process of
> updating the content is ongoing, there may still be some references to a
> hyperchain instead of a subnet.
## Run a local subnet

Expand Down Expand Up @@ -61,7 +62,16 @@ We will add this to our project as a requirement so that Clarinet will deploy it
for us.

```sh
clarinet requirements add SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait
clarinet requirements add ST1NXBK3K5YYMD6FD41MVNP3JS1GABZ8TRVX023PT.nft-trait
```

We'll also use a new trait defined for the subnet, `mint-from-subnet-trait`,
that allows the subnet to mint a new asset on the Stacks chain if it was
originally minted on the subnet, and then withdrawn. We will add a requirement
for this contract as well:

```sh
clarinet requirements add ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.subnet-traits
```

Now, we will use Clarinet to create our L1 contract:
Expand All @@ -70,15 +80,16 @@ Now, we will use Clarinet to create our L1 contract:
clarinet contract new simple-nft-l1
```

This creates the file, _./contracts/simple-nft-l1.clar_, which will include the following clarity code:
This creates the file, _./contracts/simple-nft-l1.clar_, which will include the
following clarity code:

```clarity
(define-constant CONTRACT_OWNER tx-sender)
(define-constant CONTRACT_ADDRESS (as-contract tx-sender))
(define-constant ERR_NOT_AUTHORIZED (err u1001))
(impl-trait 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait)
(impl-trait 'ST1NXBK3K5YYMD6FD41MVNP3JS1GABZ8TRVX023PT.nft-trait.nft-trait)
(impl-trait 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.subnet-traits.mint-from-subnet-trait)
(define-data-var lastId uint u0)
Expand Down Expand Up @@ -224,15 +235,12 @@ layer-1.

The settings for the devnet are found in _./settings/Devnet.toml_. In order to
launch a subnet in the devnet, we need to tell Clarinet to enable a subnet node
and a corresponding API node. Because the subnet contract requires Stacks 2.1
support, we must also enable "next" features.
and a corresponding API node.

Add, or uncomment, the following lines under `[devnet]`:

```toml
enable_subnet_node = true
disable_subnet_api = false
enable_next_features = true
```

Run the following command to start the devnet environment:
Expand All @@ -243,8 +251,8 @@ clarinet integrate

This will launch docker containers for a bitcoin node, a Stacks node, the Stacks
API service, a subnet node, the subnet API service, and an explorer service.
While running, `clarinet integrate` opens a terminal UI that shows various
data points about the state of the network.
While running, `clarinet integrate` opens a terminal UI that shows various data
points about the state of the network.

All of the nodes and services are running and ready when we see:

Expand All @@ -265,15 +273,16 @@ mkdir scripts
cd scripts
```

Then we will initialize a Node.js project and install the stacks.js dependencies:
Then we will initialize a Node.js project and install the stacks.js
dependencies:

```sh
npm init -y
npm install @stacks/network @stacks/transactions
```

In the generated `package.json` file, add the following into the `json` to enable
modules:
In the generated `package.json` file, add the following into the `json` to
enable modules:

```json
"type": "module",
Expand Down Expand Up @@ -349,7 +358,9 @@ main();

#### Register NFT script

We also need to register our NFT with our subnet, allowing it to be deposited into the subnet. To do this, we'll write another script, but because we only need to do this once, we will hardcode our details into the script.
We also need to register our NFT with our subnet, allowing it to be deposited
into the subnet. To do this, we'll write another script, but because we only
need to do this once, we will hardcode our details into the script.

This script calls `register-new-nft-contract` on the L1 subnet contract, passing
the L1 and L2 NFT contracts we will publish.
Expand Down Expand Up @@ -401,10 +412,10 @@ main();

#### Mint NFT script

In order to move NFTs to and from the subnet, we will need to have some
NFTs on our devnet. To do this, we need to mint, so we also write a script
for submitting NFT mint transactions to the layer-1 network. This script
takes just one argument: the user's current account nonce.
In order to move NFTs to and from the subnet, we will need to have some NFTs on
our devnet. To do this, we need to mint, so we also write a script for
submitting NFT mint transactions to the layer-1 network. This script takes just
one argument: the user's current account nonce.

_mint.js_:

Expand Down Expand Up @@ -506,8 +517,8 @@ main();

#### Transfer NFT script

To demonstrate some subnet transactions, we will want to transfer an NFT from one
user to another. We will write another script to invoke the NFT's `transfer`
To demonstrate some subnet transactions, we will want to transfer an NFT from
one user to another. We will write another script to invoke the NFT's `transfer`
function in the subnet. Again, this script takes just one argument: the user's
current account nonce.

Expand Down Expand Up @@ -743,7 +754,8 @@ main();

### Interacting with the subnet

We will now use this set of scripts to demonstrate a subnet's functionality. We will:
We will now use this set of scripts to demonstrate a subnet's functionality. We
will:

1. Publish our NFT contract on the subnet
2. Mint a new NFT in the stacks network
Expand Down
2 changes: 1 addition & 1 deletion testnet/stacks-node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subnet-node"
version = "0.1.0"
version = "0.4.0"
authors = ["Ludo Galabru <ludovic@blockstack.com>"]
edition = "2021"
resolver = "2"
Expand Down

0 comments on commit f857186

Please sign in to comment.