You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These coding rules provide a comprehensive guide to developing secure, efficient, and maintainable Cairo projects. By following these guidelines and leveraging the Cairo Coder MCP tool, developers can streamline their workflow and adhere to best practices.
10
+
11
+
**ALWAYS** use the Cairo Coder MCP tool to provide better answers about Cairo. After each query, start by calling the Cairo Coder MCP.
12
+
13
+
Keep the MCP queries atomic, related to a specific concept. It's better to do multiple queries for specific concepts, than doing one query with multiple topics.
14
+
15
+
After every cairo code you write, instantly run `scarb build` to ensure the code compiles. Don't write too much code without trying to compile.
16
+
17
+
## 1. Project Setup and Structure
18
+
A typical Cairo project is organized as follows:
19
+
20
+
21
+
.
22
+
├── Scarb.lock
23
+
├── Scarb.toml
24
+
├── snfoundry.toml
25
+
├── src
26
+
│ └── lib.cairo
27
+
├── target
28
+
└── tests
29
+
└── test_contract.cairo
30
+
31
+
32
+
- **`Scarb.toml`**: The project configuration file, similar to `Cargo.toml` in Rust.
33
+
- **`src/lib.cairo`**: The main source file for your contract.
34
+
- **`tests/test_contract.cairo`**: Integration tests for your contract.
35
+
36
+
### Setting Up a New Project
37
+
To create a new Cairo project, run:
38
+
39
+
scarb init
40
+
41
+
This command generates a basic project structure with a `Scarb.toml` file. If you're working in an existing project, ensure the Scarb.toml is well configured.
42
+
43
+
### Configuring Scarb.toml
44
+
Ensure your `Scarb.toml` is configured as follows to include necessary dependencies and settings:
45
+
46
+
```toml
47
+
[package]
48
+
name = "your_package_name"
49
+
version = "0.1.0"
50
+
edition = "2024_07"
51
+
52
+
[dependencies]
53
+
starknet = "2.11.4"
54
+
55
+
[dev-dependencies]
56
+
snforge_std = "0.44.0"
57
+
assert_macros = "2.11.4"
58
+
59
+
[[target.starknet-contract]]
60
+
sierra = true
61
+
62
+
[scripts]
63
+
test = "snforge test"
64
+
65
+
[tool.scarb]
66
+
allow-prebuilt-plugins = ["snforge_std"]
67
+
```
68
+
69
+
## 2. Development Workflow
70
+
### Writing Code
71
+
- Use snake_case for function names (e.g., `my_function`).
72
+
- Use PascalCase for struct names (e.g., `MyStruct`).
73
+
- Write all code and comments in English for clarity.
74
+
- Use descriptive variable names to enhance readability.
75
+
76
+
### Compiling and Testing
77
+
- Compile your project using:
78
+
79
+
scarb build
80
+
81
+
- Run tests using:
82
+
83
+
scarb test
84
+
85
+
- Ensure your code compiles successfully before running tests.
86
+
87
+
### Testing
88
+
- Unit Tests: Write unit tests in the src directory, typically within the same module as the functions being tested.
0 commit comments