This repository contains the contracts and associated tooling for Dojo.
It includes the following crates:
contracts
: the core contracts and logic for Dojo written in Cairo.types
: the Rust types related to the core contracts.compiler
: the Cairo compiler plugin for Dojo that generates the artifacts for the contracts and associated dojo manifests.
Some binaries are also included:
abigen
: a program that generates the Rust bindings for the contracts, which are written into thetypes
crate.demo-compiler
: a demo compiler that canbuild
,test
andclean
a Dojo project.
To not have to work with sozo, the demo compiler can be used to compile the contracts. The primary goal of the demo compiler is to compile and test the dojo core contracts.
cargo run -r -p demo-compiler build --manifest-path crates/contracts/Scarb.toml
cargo run -r -p demo-compiler test --manifest-path crates/contracts/Scarb.toml
cargo run -r -p demo-compiler clean --manifest-path crates/contracts/Scarb.toml
You can also compiles the examples by using the demo compiler, adjusting the path to the example Scarb.toml
file.
To expand the code generated by the plugin, you can set DOJO_EXPAND=1
.
Using cainome to generate the bindings from the Cairo ABI, the bindings must be maintained up to date with the contracts.
# Note, use `-r` to run the binary in release mode as Scarb is very slow in debug mode.
# To generate the bindings.
cargo run -r -p dojo-abigen
# To check if the bindings are up to date.
cargo run -r -p dojo-abigen -- --check
At the moment, after running the abigen, you must run the cargo fmt
to fix the formatting of the generated bindings.
Please use the following script to format the code:
./scripts/rust_fmt.sh
The examples folders are here to test the compiler support and showcase the features.
dojo_simple
: showcase a simple dojo project without any external dependencies.workspace
: showcase a dojo project with multiple crates.
When working on dojo-core
, consider the following:
You can use the dev-container available on github to avoid installing all the dependencies locally.
The devcontainer is also used in the CI pipeline. The devcontainer is built with bookworm
as the base image, which should also work on Apple Silicon.
You can re-build locally if necessary on a Apple Silicon machine using:
cd .devcontainer
sudo docker build --build-arg VARIANT=bookworm .
When rust code is modified, please ensure you're formatting the code correctly running those scripts:
./scripts/rust_fmt.sh
./scripts/clippy.sh
./scripts/docs.sh
When Cairo code is modified, please ensure you're formatting:
./scripts/cairo_fmt.sh
If you have changed the Cairo code, you will want to run the test script to fix the Cairo changes into the test. Please VERIFY the changes when running with --fix.
# PLEASE VERIFY THE GENERATED CODE IS CORRECT
./scripts/tests.sh --fix
To run the test suite that is used in the CI pipeline, you can run the following script:
./scripts/tests.sh