Skip to content

Commit e503efd

Browse files
werner-stacksgitbook-bot
authored andcommitted
GITBOOK-103: Clarinet pages: Epoch 4.0 / Clarity 6 updates (63a: local devnet, project structure, simnet-only cod
1 parent 61eaba0 commit e503efd

4 files changed

Lines changed: 146 additions & 73 deletions

File tree

‎docs/build/clarinet/local-blockchain-development.md‎

Lines changed: 78 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Clarinet ships with a complete local blockchain environment so you can build, te
1010

1111
* A devnet refers to a local blockchain development environment in which your smart contracts and front end application can interact with simulated blockchain entities.
1212
* With a devnet, your smart contract application can interact with simulated blockchain entities (miners, nodes, and a stream of mined blocks), all within your local machine.
13-
* When devnets simulate a blockchain environment, the entities created—the other contracts, transactions, or nodes—resemble the conditions your application will inhabit once in production.
13+
* When devnets simulate a blockchain environment, the entities created (the other contracts, transactions, or nodes) resemble the conditions your application will inhabit once in production.
1414
* Devnets enable you to create different blockchain configurations.
1515
* You can share a simnet environment with other devs and collaborate with them.
1616
* You can start a devnet at an arbitrary block height with a specified network upgrade at a later block, and with many simulated users, to see how your application responds.
@@ -27,19 +27,21 @@ clarinet devnet start
2727

2828
Useful flags:
2929

30-
| Option | Description |
31-
| -------------------------------- | ------------------------------------------------- |
32-
| `--manifest-path <path>` | Use an alternate `Clarinet.toml` |
33-
| `--no-dashboard` | Stream logs instead of showing the interactive UI |
34-
| `--deployment-plan-path <path>` | Apply a specific deployment plan |
35-
| `--use-on-disk-deployment-plan` | Use an existing plan without recomputing |
36-
| `--use-computed-deployment-plan` | Recompute and overwrite the plan |
37-
| `--package <path>` | Load a packaged devnet configuration |
30+
| Option | Description |
31+
| -------------------------------- | --------------------------------------------------------------------------------------- |
32+
| `--manifest-path <path>` | Use an alternate `Clarinet.toml` |
33+
| `--no-dashboard` | Stream logs instead of showing the interactive UI |
34+
| `--deployment-plan-path <path>` | Apply a specific deployment plan |
35+
| `--use-on-disk-deployment-plan` | Use an existing plan without recomputing |
36+
| `--use-computed-deployment-plan` | Recompute and overwrite the plan |
37+
| `--package <path>` | Load a packaged devnet configuration |
38+
| `--from-genesis` | Skip the embedded Epoch 4.0 snapshot and boot from genesis, walking through every epoch |
39+
| `--create-new-snapshot` | Boot from genesis and save a new global snapshot after the first Epoch 4.0 Stacks block |
3840

3941
{% hint style="info" %}
4042
Prerequisites
4143

42-
Devnet requires Docker. If you see “clarinet was unable to create network,” ensure Docker Desktop is running or the Docker daemon is started.
44+
Devnet requires Docker. If you see "clarinet was unable to create network," ensure Docker Desktop is running or the Docker daemon is started.
4345
{% endhint %}
4446

4547
By default the dashboard displays service health, recent transactions, block production, contract deployments, and resource usage. Use `--no-dashboard` in CI or when you prefer streaming logs.
@@ -167,10 +169,10 @@ curl http://localhost:3999/v2/info
167169

168170
Common endpoints:
169171

170-
* `/v2/info` – network information
171-
* `/v2/accounts/{address}` – account details
172-
* `/v2/contracts/source/{address}/{name}` – contract source code
173-
* `/extended/v1/tx/{txid}` – transaction details
172+
* `/v2/info`: network information
173+
* `/v2/accounts/{address}`: account details
174+
* `/v2/contracts/source/{address}/{name}`: contract source code
175+
* `/extended/v1/tx/{txid}`: transaction details
174176

175177
### Direct RPC
176178

@@ -184,9 +186,9 @@ curl -X POST http://localhost:20443/v2/transactions \
184186

185187
Useful RPC endpoints:
186188

187-
* `/v2/transactions` – broadcast transactions
188-
* `/v2/contracts/call-read` – read-only contract calls
189-
* `/v2/fees/transfer` – fee estimates for STX transfers
189+
* `/v2/transactions`: broadcast transactions
190+
* `/v2/contracts/call-read`: read-only contract calls
191+
* `/v2/fees/transfer`: fee estimates for STX transfers
190192

191193
## Advanced configuration
192194

@@ -207,53 +209,75 @@ disable_stacks_api = false
207209

208210
### Epoch configuration
209211

210-
Test different Stacks versions:
212+
Devnet activates each Stacks epoch at a Bitcoin block height set under `[devnet]` in `settings/Devnet.toml`. These are the Clarinet v3.24.1 defaults; a key you leave out takes the default.
211213

212214
```toml
213-
[epochs]
214-
epoch_2_0 = 0 # Stacks 2.0 from genesis
215-
epoch_2_05 = 0 # Stacks 2.05 from genesis
216-
epoch_2_1 = 0 # Stacks 2.1 from genesis
217-
epoch_2_2 = 0 # Pox-2 from genesis
218-
epoch_2_3 = 0 # Pox-3 from genesis
219-
epoch_2_4 = 0 # Pox-4 from genesis
220-
epoch_3_0 = 101 # Nakamoto activation at block 101
215+
[devnet]
216+
epoch_2_0 = 100
217+
epoch_2_05 = 100
218+
epoch_2_1 = 101
219+
epoch_2_2 = 102
220+
epoch_2_3 = 103
221+
epoch_2_4 = 104
222+
epoch_2_5 = 108
223+
epoch_3_0 = 142 # Nakamoto
224+
epoch_3_1 = 144
225+
epoch_3_2 = 146
226+
epoch_3_3 = 148
227+
epoch_3_4 = 150
228+
epoch_4_0 = 162 # PoX-5 and Clarity 6
221229
```
222230

231+
Devnet's PoX cycle is 20 Bitcoin blocks long with a 5-block prepare phase, starting at block 100. `epoch_3_0` has to fall inside a reward phase; Clarinet refuses to start otherwise and names the offending height in the error.
232+
233+
By default `clarinet devnet start` restores an embedded snapshot taken after the first Epoch 4.0 Stacks block, so the chain is in Epoch 4.0 with `pox-5` deployed as soon as the dashboard shows the network ready. Changing any `epoch_*` height makes the snapshot unusable; Clarinet prints which fields differ from the snapshot and boots from genesis instead, which takes longer because every epoch transition is mined live. `--from-genesis` forces that path without editing the file.
234+
235+
To test against PoX-5 on Devnet, keep the defaults. To test a contract's behavior across an epoch boundary, raise `epoch_4_0` so the contract deploys before it, then watch the transition in the `--no-dashboard` logs.
236+
237+
{% hint style="info" %}
238+
Devnet accounts carry an `sbtc_balance` next to `balance` in `settings/Devnet.toml` (1,000,000,000 sats for the generated wallets). Devnet funds each account's `sbtc_balance` on both snapshot and genesis boots, so sBTC-backed bond tests have a balance to draw on.
239+
{% endhint %}
240+
223241
### Custom node/signer images
224242

225-
Clarinet runs Devnet with specific tags for each Docker image. For example, Clarinet v3.10.0 uses the following images:
243+
Clarinet runs Devnet with a pinned tag for each Docker image. Clarinet v3.24.1 uses:
226244

227-
* stacks node: `blockstack/stacks-core:3.3.0.0.6-alpine`
228-
* stacks signer: `blockstack/stacks-signer:3.3.0.0.6.0-alpine`
245+
* stacks node: `ghcr.io/stacks-network/stacks-core:4.0.1-alpine`
246+
* stacks signer: `ghcr.io/stacks-network/stacks-signer:4.0.1-alpine`
229247

230-
We recommend Devnet users let Clarinet handle it and use the default version. This ensures that your Clarinet version can handle and properly configure the images it uses.
248+
Keep the defaults unless you are testing a node build. The Clarinet release pins the image that matches its epoch defaults; an older node image cannot reach `epoch_4_0`.
231249

232-
In some cases, you may need to use other images. Clarinet lets you do this by configuring it in `settings/Devnet.toml`. For example, if you don't want to run the `alpine` images:
250+
To run other images, set `stacks_node_image_url` and `stacks_signer_image_url` under `[devnet]` in `settings/Devnet.toml`. This example runs the stacks-core 4.0.4 release in its Debian build, pinned by digest so the image cannot change under the same tag:
233251

234252
```toml
235-
# setting/Devnet.toml
253+
# settings/Devnet.toml
236254
[network]
237255
name = "devnet"
238256
deployment_fee_rate = 10
239257

240258
# ...
241259

242260
[devnet]
243-
stacks_node_image_url = "blockstack/stacks-core:3.3.0.0.6"
244-
stacks_signer_image_url = "blockstack/stacks-signer:3.3.0.0.6.0"
261+
# stacks-core 4.0.4 (Debian)
262+
stacks_node_image_url = "ghcr.io/stacks-network/stacks-core@sha256:a35bf7468139469c3da248f37396d59eed51f9c4df86a9b28df73814d13d38fa"
263+
# stacks-signer 4.0.4 (Debian)
264+
stacks_signer_image_url = "ghcr.io/stacks-network/stacks-signer@sha256:af346187bc779d75daef47baaa12a0ece7fda78b5357f338d2db5536dd176608"
245265
```
246266

267+
For the Alpine builds of the same release, use the `4.0.4-alpine` tags (`ghcr.io/stacks-network/stacks-core:4.0.4-alpine` and `ghcr.io/stacks-network/stacks-signer:4.0.4-alpine`).
268+
269+
Clarinet does not compare the image when it decides whether to restore its snapshot: the check covers the `epoch_*` heights, the signer keys and the stacking orders. A custom image therefore still starts from the snapshot embedded in the Clarinet release. Add `--from-genesis` to boot the custom image from genesis instead.
270+
247271
<details>
248272

249273
<summary>Build an image locally and use it</summary>
250274

251-
* Clone the stacks-core repository (or a fork) and checkout the desired branch.
275+
* Clone the stacks-core repository (or a fork) and check out the release tag or branch you want to test.
252276

253277
```
254278
git clone git@github.com:stacks-network/stacks-core.git
255279
cd stacks-core
256-
git checkout develop
280+
git checkout 4.0.4
257281
```
258282

259283
* Build the Docker image `stacks-node:local`:
@@ -273,7 +297,7 @@ docker push localhost:5001/stacks-node:local
273297
* Set the image to be used:
274298

275299
```
276-
# setting/Devnet.toml
300+
# settings/Devnet.toml
277301
[network]
278302
name = "devnet"
279303
deployment_fee_rate = 10
@@ -287,7 +311,7 @@ stacks_node_image_url = "localhost:5001/stacks-node:local"
287311
* Then start Devnet:
288312

289313
```
290-
clarinet devnet sta
314+
clarinet devnet start
291315
```
292316

293317
</details>
@@ -312,11 +336,14 @@ $ clarinet devnet start --package demo-env.json
312336

313337
<details>
314338

315-
<summary>Docker connection errors — “clarinet was unable to create network”</summary>
339+
<summary>Docker connection errors: "clarinet was unable to create network"</summary>
316340

317341
Follow these steps to fix Docker connection issues:
318342

319-
Ensure Docker Desktop is running (macOS/Windows).Start the Docker daemon (sudo systemctl start docker) on Linux.Confirm permissions with docker ps.Reset Docker to factory defaults if problems persist.
343+
* Ensure Docker Desktop is running (macOS/Windows).
344+
* Start the Docker daemon (`sudo systemctl start docker`) on Linux.
345+
* Confirm permissions with `docker ps`.
346+
* Reset Docker to factory defaults if problems persist.
320347

321348
Verify Docker status:
322349

@@ -329,7 +356,7 @@ docker ps
329356

330357
<details>
331358

332-
<summary>Port already in use — “bind: address already in use”</summary>
359+
<summary>Port already in use: "bind: address already in use"</summary>
333360

334361
Find and stop the conflicting process (macOS/Linux):
335362

@@ -385,7 +412,7 @@ rm -rf tmp/devnet
385412

386413
<details>
387414

388-
<summary>Network already exists — “network with name `.devnet` already exists”</summary>
415+
<summary>Network already exists: "network with name `.devnet` already exists"</summary>
389416

390417
Remove the orphaned network:
391418

@@ -410,7 +437,7 @@ docker network prune
410437

411438
<details>
412439

413-
<summary>Docker stream error during startup — “Fatal: unable to create image: Docker stream error”</summary>
440+
<summary>Docker stream error during startup: "Fatal: unable to create image: Docker stream error"</summary>
414441

415442
**Error**: "Fatal: unable to create image: Docker stream error"
416443

@@ -487,4 +514,12 @@ clarinet deployments apply --devnet
487514

488515
</details>
489516

517+
<details>
518+
519+
<summary>Epoch settings have no effect</summary>
520+
521+
Older versions of this page showed the epoch keys in a top-level `[epochs]` table. Clarinet reads them only under `[devnet]`. Move the keys there and start Devnet again.
522+
523+
</details>
524+
490525
***

‎docs/build/clarinet/project-structure.md‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,17 @@ description = "A counter smart contract"
4545

4646
[contracts.traits]
4747
path = "contracts/traits.clar"
48-
clarity_version = 4
48+
clarity_version = 6
4949
epoch = "latest"
5050

5151
[contracts.counter]
5252
path = "contracts/counter.clar"
53-
clarity_version = 4
53+
clarity_version = 6
5454
epoch = "latest"
5555
```
5656

57+
`clarinet contract new` writes these two keys for you. Clarinet v3.24.1 accepts `clarity_version` values 1 through 6.
58+
5759
The manifest handles several critical functions:
5860

5961
* **Contract registration**: Every contract must be listed here
@@ -62,19 +64,27 @@ The manifest handles several critical functions:
6264

6365
### Epoch configuration
6466

65-
You can specify the epoch in two ways:
67+
Set the epoch per contract, either to a specific version or to the current mainnet epoch:
6668

6769
```toml
68-
# Use a specific epoch version
69-
epoch = 3.1
70+
# A specific epoch. Accepted: 2.0, 2.05, 2.1, 2.2, 2.3, 2.4, 2.5, 3.0, 3.1, 3.2, 3.3, 3.4, 4.0
71+
epoch = 4.0
7072
```
7173

7274
```toml
73-
# Use the latest available epoch (default)
75+
# The epoch running on mainnet, as pinned by your Clarinet release (default for new contracts)
7476
epoch = "latest"
7577
```
7678

77-
Using `"latest"` ensures your contracts always use the newest Clarity features and optimizations available in your version of Clarinet.
79+
`"latest"` means the epoch active on mainnet, which Clarinet v3.24.1 pins to 4.0. It is not the newest epoch the Clarity VM knows about, so a contract marked `"latest"` deploys with the features mainnet has today.
80+
81+
The two keys depend on each other:
82+
83+
* `epoch` set, `clarity_version` omitted: Clarinet uses the default Clarity version for that epoch. Epoch 4.0 defaults to Clarity 6.
84+
* Both omitted: Clarinet falls back to epoch 2.05 and Clarity 1, which rejects most current syntax. Set both.
85+
* `clarity_version` newer than the epoch supports: `clarinet check` stops with `Clarity 6 can not be used with 3.4` (the message names your values).
86+
87+
A contract that calls `pox-5` or implements its `signer-manager-trait` needs `epoch = 4.0` or `"latest"`, because `pox-5` does not exist in earlier epochs; any `clarity_version` up to 6 compiles in that epoch. Pick Clarity 6 when the contract uses what Clarity 6 added: the `with-staking` and `with-pox` allowances for `restrict-assets?` and `as-contract?`, `get-bitcoin-tx-output?`, `verify-merkle-proof`, `ed25519-verify`, `secp256k1-decompress?`, or variadic `concat`. In Clarity 4 and 5 contracts the allowance keeps its old spelling, `with-stacking`; the `renamed_builtin` lint in `clarinet check` flags it once the contract's `clarity_version` is 6.
7888

7989
## Testing infrastructure
8090

‎docs/build/clarinet/simnet-only-code.md‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description: Documentation and use cases for conditional code deployment with Clarinet
33
---
44

5-
# Simnet-only code deployment
5+
# Simnet-only code
66

77
Clarinet 3.17.0 introduced conditional code deployment, letting you write Clarity expressions that Clarinet only deploys in Simnet and never on-chain.
88

@@ -77,12 +77,20 @@ This feature only works at the tooling level, in Clarinet. If you deploy a contr
7777

7878
Smart contracts sometimes need to behave differently on testnet and mainnet. Simnet-only code deployment only covers Simnet vs "real-nets" (Devnet/Testnet/Mainnet). We may expand conditional deployments to more environments and conditions in the future, but we want to keep it simple for now.
7979

80-
If a smart contract needs different behavior on testnet vs mainnet, take a look at how the PoX contracts handle it (for example [pox-4](https://explorer.hiro.so/txid/SP000000000000000000002Q6VF78.pox-4?chain=mainnet&tab=sourceCode)) using `is-in-mainnet`:
80+
If a smart contract needs different behavior on testnet and mainnet, look at how the PoX contracts handle it. `pox-5`, the contract deployed at `SP000000000000000000002Q6VF78.pox-5`, sets its cycle lengths with `is-in-mainnet`:
8181

8282
```clarity
83-
;; Default length of the PoX registration window, in burnchain blocks.
84-
(define-constant PREPARE_CYCLE_LENGTH (if is-in-mainnet u100 u50))
85-
86-
;; Default length of the PoX reward cycle, in burnchain blocks.
87-
(define-constant REWARD_CYCLE_LENGTH (if is-in-mainnet u2100 u1050))
83+
;; Data vars that store a copy of the burnchain configuration.
84+
;; Implemented as data-vars, so that different configurations can be
85+
;; used in e.g. test harnesses.
86+
(define-data-var pox-prepare-cycle-length uint (if is-in-mainnet
87+
u100
88+
u50
89+
))
90+
(define-data-var pox-reward-cycle-length uint (if is-in-mainnet
91+
u2100
92+
u1050
93+
))
8894
```
95+
96+
`is-in-mainnet` is evaluated when the contract is deployed, so the same source gives mainnet a 2,100-block reward cycle with a 100-block prepare phase and testnet a 1,050-block cycle with a 50-block prepare phase. pox-5 uses the same keyword to pick the address version when it reconstructs a signer principal. Read the [deployed contract](https://explorer.hiro.so/txid/SP000000000000000000002Q6VF78.pox-5?chain=mainnet\&tab=sourceCode) or the [source at release 4.0.4](https://github.com/stacks-network/stacks-core/blob/4.0.4/stackslib/src/chainstate/stacks/boot/pox-5.clar#L356-L366).

0 commit comments

Comments
 (0)