stacksdapp generate parses Clarity contract ABIs and writes type-safe TypeScript bindings plus a debug UI under frontend/src/generated/.
Contents
- Generate once
- Watch mode
- How it works
- Generated files
- Using hooks in your UI
- Hiro API key (optional)
- Stale deployments
- File watcher during dev
Generate once
package-lock.json exists under contracts/ or frontend/, generate runs npm ci before exporting ABIs.
Watch mode
Regenerate on every.clar change without the full dev supervisor:
stacksdapp generate --watch regenerates bindings when you save a contract. stacksdapp dev does not.
How it works
1. Parse
Extract ABIs from all contracts usinginitSimnet():
contracts/.cache/. Unchanged sources skip redundant initSimnet runs.
2. Normalize
3. Render
Tera templates produce three files underfrontend/src/generated/:
contracts.ts: typed call wrappershooks.ts: React hooksDebugContracts.tsx: live debug panel
4. Write
SHA-256 hashing writes only when content changes. This keeps Next.js hot reload fast.Generated files
contracts.ts
hooks.ts
DebugContracts.tsx
deployments.json
Contract addresses written bystacksdapp deploy.
Using hooks in your UI
Hiro API key (optional)
For higher rate limits on read-only Stacks calls, set infrontend/.env.local:
getReadOnlyNetwork (@stacks/network v7).
Stale deployments
If on-chain addresses indeployments.json no longer match your contracts, redeploy:
File watcher
stacksdapp dev does not watch contracts. Run this in another terminal:
- Monitors
.clarfiles - Debounces rapid edits
- Runs code generation
- Lets Next.js hot reload pick up the new bindings