Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

pixelaw/game

Repository files navigation

PixeLAW Game

A game built on top of Dojo. See live example here

Prerequisites

  • Rust - install here
  • Cairo language server - install here
  • Dojo - install here
  • Scarb - install here
  • NodeJS - install here

Developing Locally

Step 1: Build the contracts

make build

This command compiles your project and prepares it for execution.

Step 2: Start Dojo Forkserver

The Dojo Forkserver is a container that has the Katana RPC, the Torii World Indexer, and a Forkserver Dashboard. Once the container starts, it starts running Katana, deploys the World Container from the repo via the contracts volume (See the docker-compose.yml for more details), runs the post_deploy script from the repo's Scarb.toml, and starts up Torii. The Dojo Forkserver Dashboard is accesible via http://localhost:3000/fork.

make start_container

Step 3: Get the React frontend ready

make prep_web
cd web
yarn

Step 4: Run the frontend locally

cd web
yarn dev

Step 5: Run the queue bot

cd bots
yarn install
yarn dev

NOTE

To change accounts, add an account query to the frontend url. For example: http://localhost:3000/?account=1. Add as many accounts as desired by following the pattern set in the env.example.

The following would be example players:

# for player 1
http://localhost:5173/?account=1
# for player 2
http://localhost:5173/?account=2

Project Structure

This is an overview of the most important folders/files:

  • Makefile : A collection of helpful commands, mainly for Dojo
  • contracts : The Dojo Cairo smart contract code
    • src/components.cairo : Dojo component definitions
    • src/systems.cairo : Dojo component definitions
    • src/Scarb.toml : The scarb config file used for katana
  • web : A Vite React project
    • .env : (copied from env.example) Contains the hardcoded developer addresses used for Dojo
    • src/dojo/contractComponents.ts : Client-side definitions of the components
    • src/dojo/createClientComponents.ts : Client-side setup of the components
    • src/dojo/createSystemCalls.ts : Client-side definitions of the systems

Typical development activities

Add a DOJO system

  • Edit src/systems.cairo
  • Edit src/dojo/createSystemCalls.ts

Add a DOJO component

  • Edit src/components.cairo
  • Edit src/dojo/contractComponents.ts
  • Edit src/dojo/createClientComponents.ts

Redeploy to Katana

  • Restart Katana
  • Redeploy the contracts with cd contracts && scarb run deploy

Troubleshooting / Tricks

When using vscode, the cairo language server panics with thread 'main' panicked at 'internal error: entered unreachable code:

Resolution: None, this is a know issue, can ignore

When deploying/migrating, consistent exceptions even though the contract compiles.

Resolution: Delete the contracts/target dir

How do I use different accounts while testing?

Register 2 accounts (example from https://github.com/coostendorp/dojo-rps):

let player1 = starknet::contract_address_const::<0x1337>();
let player2 = starknet::contract_address_const::<0x1338>();

And then switch accounts like this:

starknet::testing::set_contract_address(player1);