01 — Hello Contract
The minimal viable Covenant file: a record with one field, one setter action, and one read view. This is the canonical starting point.
-- Hello.cov · the minimal viable Covenant file.
-- A `record` is a key-value store on chain: fields + actions + views,
-- nothing else. The simplest building block in the language.
record Hello {
greeting: text
action update(new_text: text) {
greeting = new_text
}
view read returns text {
greeting
}
}
What just happened?
| Concept | Explanation |
|---|---|
-- | Single-line comment (Covenant uses Haskell-style, not //) |
record | Top-level keyword: a key-value store on chain |
greeting: text | Field declaration; text is the UTF-8 string type. Inside record the field keyword is implicit |
action update(...) | State-mutating function. Default visibility is external — no public/external modifier needed |
view read returns text | Read-only query. Zero-arg views drop the parentheses — write view read returns text, not view read() returns text |
(no return keyword in body) | Single-expression view bodies are expression-bodied: the last expression is the return value |
Try it now — no install required
The button opens the Covenant Playground with this contract pre-loaded. From there:
- Compile — the Inspector panel shows real EVM bytecode + ABI
- Deploy (target: MockChain) — the contract gets a deterministic address in ~50ms
- In Interaction Panel, find
update, type a string, click Call - Find
read, click Query — returns what you just set
Switch the Chain Target to Sepolia to deploy to a real testnet via MetaMask (~30s with confirmation).
Build it locally (CLI)
covenant new hello-world
cd hello-world
# replace src/main.cov with the snippet above
covenant build # emits hello-world.abi + hello-world.bin
covenant test # runs the snapshot test suite
Continue
Move on to 02 — Fields & Storage to see how to declare more complex state.