Skip to content

Commit d36ebd6

Browse files
Add some more tutorial documentation (#60)
1 parent 24e92f2 commit d36ebd6

File tree

15 files changed

+408
-263
lines changed

15 files changed

+408
-263
lines changed

docs/src/.vuepress/config.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,26 @@ module.exports = {
4242
title: "Getting Started",
4343
children: [
4444
"/getting-started/introduction",
45-
"/getting-started/installation",
46-
"/getting-started/quick-start",
45+
"/getting-started/installation",
4746
],
4847
},
4948
{
5049
collapsable: false,
51-
title: "Tutorials",
52-
children: [
50+
title: "Programs on Solana",
51+
children: [
5352
"/tutorials/tutorial-0",
5453
"/tutorials/tutorial-1",
5554
"/tutorials/tutorial-2",
5655
"/tutorials/tutorial-3",
5756
"/tutorials/tutorial-4",
57+
"/tutorials/tutorial-5",
58+
],
59+
},
60+
{
61+
collapsable: false,
62+
title: "CLI",
63+
children: [
64+
"/cli/commands",
5865
],
5966
},
6067
],

docs/src/cli/commands.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# Commands
2+
3+
A CLI is provided to support building and managing an Anchor workspace.
4+
For a comprehensive list of commands and options, run `anchor -h` on any
5+
of the following subcommands.
6+
7+
```
8+
anchor-cli
9+
10+
USAGE:
11+
anchor <SUBCOMMAND>
12+
13+
FLAGS:
14+
-h, --help Prints help information
15+
-V, --version Prints version information
16+
17+
SUBCOMMANDS:
18+
build Builds the workspace
19+
deploy Deploys each program in the workspace
20+
idl Commands for interacting with interface definitions
21+
init Initializes a workspace
22+
launch Deploys, initializes an IDL, and migrates all in one command
23+
migrate Runs the deploy migration script
24+
new Creates a new program
25+
test Runs integration tests against a localnetwork
26+
upgrade Upgrades a single program. The configured wallet must be the upgrade authority
27+
```
28+
29+
## Init
30+
31+
```
32+
anchor init
33+
```
34+
35+
Initializes a project workspace wit the following structure.
36+
37+
* `Anchor.toml`: Anchor configuration file.
38+
* `programs/`: Directory for Solana program crates.
39+
* `app/`: Directory for your application frontend.
40+
* `tests/`: Directory for JavaScript integration tests.
41+
* `migrations/deploy.js`: Deploy script.
42+
43+
## Build
44+
45+
```
46+
anchor build
47+
```
48+
49+
Builds programs in the workspace targeting Solana's BPF runtime and emitting IDLs in the `target/idl` directory.
50+
51+
## Deploy
52+
53+
```
54+
anchor deploy
55+
```
56+
57+
Deploys all programs in the workspace to the configured cluster.
58+
59+
::: tip Note
60+
This is different from the `solana program deploy` command, because everytime it's run
61+
it will generate a *new* program address.
62+
:::
63+
64+
## Upgrade
65+
66+
```
67+
anchor upgrade <target/deplooy/program.so> --program-id <program-id>
68+
```
69+
70+
Uses Solana's upgradeable BPF loader to upgrade the on chain program code.
71+
72+
## Test
73+
74+
```
75+
anchor test
76+
```
77+
78+
Run an integration test suit against the configured cluster, deploying new versions
79+
of all workspace programs before running them.
80+
81+
If the configured network is a localnet, then automatically starts the localnetwork and runs
82+
the test.
83+
84+
::: tip Note
85+
The Anchor workflow [recommends](https://www.parity.io/paritys-checklist-for-secure-smart-contract-development/)
86+
to test your program using integration tests in a language other
87+
than Rust to make sure that bugs related to syntax misunderstandings
88+
are coverable with tests and not just replicated in tests.
89+
:::
90+
91+
## Migrate
92+
93+
```
94+
anchor migrate
95+
```
96+
97+
Runs the deploy script located at `migrations/deploy.js`, injecting a provider configured
98+
form the workspace's `Anchor.toml`. For example,
99+
100+
```javascript
101+
// File: migrations/deploys.js
102+
103+
const anchor = require("@project-serum/anchor");
104+
105+
module.exports = async function (provider) {
106+
anchor.setProvider(provider);
107+
108+
// Add your deploy script here.
109+
}
110+
```
111+
112+
Migrations are a new feature
113+
and only support this simple deploy script at the moment.
114+
115+
## Idl
116+
117+
The `idl` subcommand provides commands for interacting with interface definition files.
118+
It's recommended to use these commands to store an IDL on chain, at a deterministic
119+
address, as a function of nothing but the the program's ID. This
120+
allow us to generate clients for a program using nothing but the program ID.
121+
122+
### Idl Init
123+
124+
```
125+
anchor idl init -f <target/idl/program.json> <program-id>
126+
```
127+
128+
Creates an idl account, writing the given `<target/idl/program.json>` file into a program owned account. By default, the size of the account is double the size of the IDL,
129+
allowing room for growth in case the idl needs to be upgraded in the future.
130+
131+
### Idl Fetch
132+
133+
```
134+
anchor idl fetch -o <out-file.json> <program-id>
135+
```
136+
137+
Fetches an IDL from the configured blockchain. For example, make sure
138+
your `Anchor.toml` is pointing to the `mainnet` cluster and run
139+
140+
```
141+
anchor idl fetch GrAkKfEpTKQuVHG2Y97Y2FF4i7y7Q5AHLK94JBy7Y5yv
142+
```
143+
144+
### Idl Authority
145+
146+
```
147+
anchor idl authority <program-id>
148+
```
149+
150+
Outputs the IDL account's authority. This is the wallet that has the ability to
151+
update the IDL.
152+
153+
### Idl Erase Authority
154+
155+
```
156+
anchor idl erase-authority -p <program-id>
157+
```
158+
159+
Erases the IDL account's authority so that upgrades can no longer occur. The
160+
configured wallet must be the current authority.
161+
162+
### Idl Upgrade
163+
164+
```
165+
anchor idl upgrade <program-id> -f <target/idl/program.json>
166+
```
167+
168+
Upgrades the IDL file on chain to the new `target/idl/program.json` idl.
169+
The configured wallet must be the current authority.
170+
171+
```
172+
anchor idl set-authority -n <new-authority> -p <program-id>
173+
```
174+
175+
Sets a new authority on the IDL account. Both the `new-authority` and `program-id`
176+
must be encoded in base 58.
177+
178+
## Launch
179+
180+
```
181+
anchor launch
182+
```
183+
184+
Builds, deploys and migrates, all in one command. This is particularly
185+
useful when simultaneously developing an app against a Localnet or Devnet. For mainnet, it's
186+
recommended to run each command separately, since transactions can sometimes be
187+
unreliable depending on the Solana RPC node being used.
188+
189+
## New
190+
191+
```
192+
anchor new <program-name>
193+
```
194+
195+
Creates a new program in the workspace's `programs/` directory initialized with boilerplate.

docs/src/getting-started/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ rustup component add rustfmt
1515

1616
## Install Solana
1717

18-
See the solana [docs](https://docs.solana.com/cli/install-solana-cli-tools) for installation instructions. Version 1.5.0 is required. On macOS and Linux,
18+
See the solana [docs](https://docs.solana.com/cli/install-solana-cli-tools) for installation instructions. Version 1.5.5 is required. On macOS and Linux,
1919

2020
```bash
21-
sh -c "$(curl -sSfL https://release.solana.com/v1.5.0/install)"
21+
sh -c "$(curl -sSfL https://release.solana.com/v1.5.5/install)"
2222
```
2323

2424
## Install Mocha

docs/src/getting-started/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Anchor is a framework for Solana's [Sealevel](https://medium.com/solana-labs/sealevel-parallel-processing-thousands-of-smart-contracts-d814b378192) runtime providing several convenient developer tools.
44

5-
- Rust crates and DSL for writing Solana programs
5+
- Rust crates and eDSL for writing Solana programs
66
- [IDL](https://en.wikipedia.org/wiki/Interface_description_language) specification
77
- TypeScript package for generating clients from IDL
88
- CLI and workspace management for developing complete applications

docs/src/getting-started/quick-start.md

Lines changed: 0 additions & 63 deletions
This file was deleted.

docs/src/tutorials/tutorial-0.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Tutorial 0: A Minimal Example
1+
# A Minimal Example
22

33
Here, we introduce Anchor's core syntax elements and project workflow. This tutorial assumes all
44
[prerequisites](../getting-started/installation.md) are installed.
@@ -65,7 +65,7 @@ anchor build
6565
The `build` command is a convenience combining two steps.
6666

6767
1) `cargo build-bpf`
68-
2) `anchor idl -f program/src/lib.rs -o target/idl/basic_0.json`.
68+
2) `anchor idl parse -f program/src/lib.rs -o target/idl/basic_0.json`.
6969
:::
7070

7171
Once run, you should see your build artifacts, as usual, in your `target/` directory. Additionally,

docs/src/tutorials/tutorial-1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Tutorial 1: Arguments and Accounts
1+
# Arguments and Accounts
22

33
This tutorial covers the basics of creating and mutating accounts using Anchor.
44
It's recommended to read [Tutorial 0](./tutorial-0.md) first, as this tutorial will

0 commit comments

Comments
 (0)