Skip to content

Commit

Permalink
docs: update quick start part
Browse files Browse the repository at this point in the history
  • Loading branch information
0xshora committed Dec 8, 2023
1 parent e176eb6 commit 42b6442
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 110 deletions.
6 changes: 2 additions & 4 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@

- [Quick Start](./getting-started/quick-start.md)
- [Development Setup](./getting-started/setup.md)
- [Contributing](./getting-started/contributing.md)

# Community

- [Get Started](./community/get-started.md)
# Community&Contribution

- [Get Started](./cc/get-started.md)

# Architecture

Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions src/getting-started/contributing.md

This file was deleted.

6 changes: 5 additions & 1 deletion src/getting-started/quick-start.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# QucikStart

To set up your environment, please see [here](./setup.md). To contribute PixeLAW, please check it out [contribution guide](./contributing.md)
Play PixeLAW first optimally. Currently, the playtest is closed. So please contact us on [Discord](https://t.co/jKDjNbFdZ5).

But you can set up your local environment and play. Please check out [here](./setup.md).

To deep dive into PixeLAW, please try [tutorial](../tutorial/readme.md).
116 changes: 15 additions & 101 deletions src/getting-started/setup.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Set up local environment

## Clone app_template

Please go to [app_template](https://github.com/pixelaw/app_template). And clone it.

```bash
$ git clone git@github.com:pixelaw/app_template.git
```

## Prerequisites

Download these libraries.

- Rust - install [here](https://www.rust-lang.org/tools/install)
- Cairo language server - install [here](https://book.dojoengine.org/development/setup.html#3-setup-cairo-vscode-extension)
- Dojo - install [here](https://book.dojoengine.org/getting-started/quick-start.html)
Expand All @@ -11,106 +22,9 @@

## Developing Locally

### Step1: Build the contracts

```shell
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](https://book.dojoengine.org/framework/katana/overview.html),
the [Torii World Indexer](https://book.dojoengine.org/framework/torii/overview.html), 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.

```shell
make start_keiko
```

### Step 3: Get the React frontend ready

```shell
make prep_web
cd web
yarn
Easiest way to deploy PixeLAW is just running this command in `app_template` folder:
```bash
$ docker compose up -d
```

### Step 4: Run the frontend locally

```shell
cd web
yarn dev
```

### Step 5: Run the queue bot
````shell
cd bots
yarn install
yarn dev
````
- to run here, you can check this page: https://www.npmjs.com/package/canvas
- the following command might fix your issue.
````shell
brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
````


#### 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:
````console
# 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](https://vitejs.dev/) 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):
```rust,ignore
let player1 = starknet::contract_address_const::<0x1337>();
let player2 = starknet::contract_address_const::<0x1338>();
```
And then switch accounts like this:
```rust,ignore
starknet::testing::set_contract_address(player1);
```
If you fail, please read [app_template README](https://github.com/pixelaw/app_template) to see another way to deploy. Or you can check [here](./setup_old.md).
116 changes: 116 additions & 0 deletions src/getting-started/setup_old.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Set up local environment

## Prerequisites
- Rust - install [here](https://www.rust-lang.org/tools/install)
- Cairo language server - install [here](https://book.dojoengine.org/development/setup.html#3-setup-cairo-vscode-extension)
- Dojo - install [here](https://book.dojoengine.org/getting-started/quick-start.html)
- Scarb - install [here](https://docs.swmansion.com/scarb/download)
- NodeJS - install [here](https://nodejs.org/en/download)
- Docker - install [here](https://docs.docker.com/engine/install/)
- Docker compose plugin - install [here](https://docs.docker.com/compose/install/)

## Developing Locally

### Step1: Build the contracts

```shell
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](https://book.dojoengine.org/framework/katana/overview.html),
the [Torii World Indexer](https://book.dojoengine.org/framework/torii/overview.html), 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.

```shell
make start_keiko
```

### Step 3: Get the React frontend ready

```shell
make prep_web
cd web
yarn
```

### Step 4: Run the frontend locally

```shell
cd web
yarn dev
```

### Step 5: Run the queue bot
````shell
cd bots
yarn install
yarn dev
````
- to run here, you can check this page: https://www.npmjs.com/package/canvas
- the following command might fix your issue.
````shell
brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
````


#### 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:
````console
# 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](https://vitejs.dev/) 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):
```rust,ignore
let player1 = starknet::contract_address_const::<0x1337>();
let player2 = starknet::contract_address_const::<0x1338>();
```
And then switch accounts like this:
```rust,ignore
starknet::testing::set_contract_address(player1);
```

0 comments on commit 42b6442

Please sign in to comment.