dojo-model

Generate Cairo Dojo model structs with key fields and Serde traits.

53|92|Updated Mar 28, 2023
One-click install
npx skills add https://github.com/dojoengine/book --skill dojo-model
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dojo-model
Source: https://github.com/dojoengine/book/tree/main/skills/dojo-model
Command: npx skills add https://github.com/dojoengine/book --skill dojo-model

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Create Dojo models to store and manage game state using ECS patterns, with correct key definitions and trait derivations to ensure reliable persistence and querying.

Core Features & Use Cases

  • Generate Cairo model structs annotated with #[dojo::model], including required traits (Drop, Serde) and a #[key] field to define the storage key.
  • Support composite keys (multiple #[key] fields) for complex relationships and ECS composition across entities and resources.
  • Provide guidance on common game-state patterns (Player, Position, Health, Inventory) and how to extend to new concepts.

Quick Start

Create a Position model with player as the key and coordinates x, y.

Frequently Asked Questions about dojo-model

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define Dojo models for ECS game state in Cairo?

To define Dojo models for ECS game state in Cairo, generate model structs annotated with #[dojo::model], include a #[key] field, and derive required traits like Drop and Serde for on-chain serialization and persistence.

How does composite key generation work for Dojo models?

Composite keys in Dojo models use multiple #[key] fields to define storage keys for complex relationships. This enforces strict key ordering to ensure reliable querying and ECS composition across entities and resources.

What traits do I need to derive for Cairo Dojo models to ensure on-chain storage?

Cairo Dojo models require Serde for serialization and Drop traits to ensure reliable on-chain storage persistence. These trait derivations are mandatory when annotating structs with #[dojo::model].

Can I use Dojo models to store common game-state patterns like Player Health and Inventory?

Dojo models support common game-state patterns like Player, Position, Health, and Inventory using ECS architecture. You define them as model structs with appropriate key fields and trait derivations for persistence.

Does key ordering matter when defining multiple key fields in Dojo models?

Key ordering is strictly enforced when defining multiple #[key] fields in Dojo models. Correct ordering is required to ensure composite keys generate proper storage keys and reliable querying.

What is the best way to structure entities and resources using ECS patterns in Dojo?

The best way to structure entities and resources in Dojo is using ECS patterns with model structs annotated by #[dojo::model], defining #[key] fields for storage, and deriving Serde for serialization.