# Cairo Contract Authoring

> Guides Cairo smart-contract authoring on Starknet with language fundamentals, safe structure choices, component composition, and implementation workflow references.

- Skill: `cartridge-gg/cairo-contract-authoring` (Agent Skill, multi-file: 7 files)
- Install (CLI): `npx skillmds@latest add cartridge-gg/cairo-contract-authoring`
- Raw SKILL.md: https://api.skillmd.com/api/skills/cartridge-gg/cairo-contract-authoring/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- License: Apache-2.0
- Author: cartridge-gg (https://skillmd.com/u/cartridge-gg)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/cartridge-gg/cairo-contract-authoring

---


# Cairo Contract Authoring

Use this as the entrypoint for implementation decisions; load references only as needed.

## When to Use

- Checking Cairo language fundamentals that directly affect contract behavior (ownership, refs, traits, generics).
- Writing a new Starknet contract.
- Modifying storage/events/interfaces.
- Composing OpenZeppelin Cairo components.

## When NOT to Use

- Gas/performance tuning (`cairo-optimization`).
- Test strategy design (`cairo-testing`).
- Deployment and release operations (`cairo-toolchain`).

## Quick Start

1. Define interface and storage boundaries first.
2. Implement minimal external/write surface.
3. Add explicit auth and invariant checks.
4. Add tests before broadening feature surface.
5. Run the authoring-to-audit handoff flow, then `cairo-auditor`.

## Security-Critical Rules

- Timelock checks must read time from Starknet syscalls (`get_block_timestamp`), never from caller-provided arguments.
- Every `#[external(v0)]` function that mutates storage must have explicit access posture:
  - guarded (`assert_only_owner` / role checks), or
  - intentionally public with a code comment stating why.
- Upgrade flows must reject zero class hash inputs before applying state transitions.
- Use anti-pattern/secure-pattern pairs to keep authoring behavior explicit and reviewable.
- If any of these rules fail in fixture benchmarks, update both:
  - skill/reference text, and
  - deterministic cases in `../evals/cases/contract_skill_benchmark.jsonl`, and
  - generation cases in `../evals/cases/contract_skill_generation_eval.jsonl`.

## Workflow

- Main authoring flow: [default workflow](workflows/default.md)

## References

- Detailed authoring reference: [legacy reference](references/legacy-full.md)
- Cairo language fundamentals reference: [language reference](references/language.md)
- Build-side anti-pattern pairs: [anti-pattern pairs](references/anti-pattern-pairs.md)
- Authoring to audit execution path: [audit handoff](references/audit-handoff.md)
- Module index: [references index](references/README.md)

