Your first workspace
⏱ 8 min · 🎯 you'll have: a freshly scaffolded Anchor workspace, building locally.
We'll create an empty workspace, look at what was generated, and run our first build.
Pre-requisites
sunscreeninstalled (Installing).anchorCLI on your PATH (anchor --versionshould print a version). If missing, install via AVM.cargo(comes with Rust).
Don't have everything? Run sunscreen doctor first — it tells you exactly what's missing.
Step 1 — Create
sunscreen chain new my-app --framework anchor --frontend none
You'll see progress output, then a summary similar to:
✓ workspace my-app/ created (anchor, no frontend)
--frontend accepts none, vite, or next. Pick vite if you want React + Vite scaffolded under app/; pick next for a Next.js scaffold. none keeps the workspace lean.
cd my-app
tree -L 2 -I node_modules
my-app/
├── Anchor.toml
├── Cargo.toml
├── package.json
├── programs/
│ └── my_app/
│ ├── Cargo.toml
│ └── src/
│ └── lib.rs
├── sunscreen.yml ← sunscreen's config (the source of truth)
├── tests/
│ └── my_app.ts
└── target/
The interesting files:
sunscreen.yml— your project config. Programs, plugins, runtime settings.programs/my_app/src/lib.rs— the Anchor program. Has// sunscreen:begin ... endmarkers that sunscreen can edit on later commands without breaking what you wrote in between.Anchor.toml— standard Anchor config, points at the program.
The markers in lib.rs are how sunscreen does incremental edits. When you run sunscreen scaffold instruction Foo later, it injects code only into marked regions. Your hand-written code is left alone. Read more in Incremental scaffolding.
sunscreen chain build
This runs anchor build under the hood and reports progress as NDJSON lines (one event per line, useful for editor integrations). On success:
✓ anchor build
✓ codama clients regenerated (skipped: no frontend)
Behind the scenes:
anchor buildproducedtarget/idl/my_app.jsonand the program's.so.- Sunscreen skipped Codama client generation because we picked
--frontend none.
Step 4 — Add an instruction
sunscreen scaffold instruction Greet --program my_app
Open programs/my_app/src/lib.rs — you'll see a new pub fn greet(...) handler inside the program module, registered in the dispatch. The marker regions made the edit safe.
Re-run the same command:
sunscreen scaffold instruction Greet --program my_app
# error: instruction "Greet" already exists in program "my_app" (exit code 4)
Idempotent: sunscreen refuses to clobber. Use --force if you really want to regenerate.
What just happened
- One command (
chain new) gave you a buildable Anchor workspace plus sunscreen's own config. - The generated code has marker comments that let sunscreen safely edit the same files in later runs.
chain buildis a thin orchestration overanchor build+ Codama generation.scaffold instructionmutated marked regions only, leaving your code untouched.
Next
- Your first NFT in 10 minutes — chain
init+ scaffold + deploy. - Scaffolding a CRUD resource — composite recipes.
- Incremental scaffolding — the marker model in depth.