Writing Your First Spell
Create a simple spell from scratch, compile it, and run it.
Goal
Write a spell that takes a parameter, uses it in logic, and emits an event. This introduces the basic spell structure without touching any protocols.
1. Create the Spell File
Create a file called spells/hello-grimoire.spell:
spell HelloGrimoire {
version: "0.1.0"
description: "My first Grimoire spell"
params: {
amount: 42
}
on manual: {
emit("hello", { value: params.amount })
}
}
This spell:
- Declares a parameter
amountwith a default value of42 - Triggers manually (not on a schedule)
- Emits an event with the parameter value
2. Compile
grimoire compile spells/hello-grimoire.spell --prettyThis shows the compiled intermediate representation (IR). If there are syntax errors, the compiler will tell you exactly what to fix.
3. Validate
grimoire validate spells/hello-grimoire.spellValidation goes beyond compilation — it checks structural rules, type consistency, and constraint validity.
4. Simulate
grimoire simulate spells/hello-grimoire.spell --chain 1Simulation runs the full preview. Since this spell has no onchain actions, it will complete without needing wallet credentials.
5. Override Parameters
You can override default parameter values at runtime:
grimoire simulate spells/hello-grimoire.spell \
--chain 1 \
--params '{"amount": 100}'6. Inspect the Run
grimoire history
grimoire log --lastThe history shows your run, and the log shows every event that occurred — including the hello event with your parameter value.
Next Steps
- Running Spells — learn the full preview-to-commit flow for spells that move value
- Venues & Adapters — see which protocols you can interact with
- CLI Reference — all command options