Auto-Code Generation
Scaffold Stacks automatically generates type-safe TypeScript code from your Clarity contracts.How it works
Thestacksdapp generate command runs in four stages:
1. Parse
Extract ABIs from all contracts usinginitSimnet():
2. Normalize
Convert Clarity types to TypeScript:| Clarity | TypeScript |
|---|---|
uint | bigint |
int | bigint |
bool | boolean |
string-ascii | string |
string-utf8 | string |
principal | string |
tuple | object |
list | array |
3. Render
Generate three files using Tera templates:contracts.ts: Direct call wrappershooks.ts: React hooksDebugContracts.tsx: Debug UI
4. Write
Update files only if content changed (preserves hot reload).Generated files
contracts.ts
Type-safe wrappers for contract calls:hooks.ts
React hooks for easy integration:DebugContracts.tsx
Interactive debug panel:File watcher
Duringstacksdapp dev, the file watcher:
- Monitors
.clarfiles for changes - Debounces rapid edits
- Runs code generation
- Triggers Next.js hot reload
Customization
The generation is driven by Tera templates in the CLI. Advanced users can:- Extend type mappings
- Add custom hooks
Performance
- SHA-256 hashing prevents unnecessary writes
- Incremental generation on changes only
- Fast TypeScript compilation
- Optimized for development workflow