This project implements a chess game on the Phala Network, utilizing off-chain computations to handle chess moves. This approach significantly enhances efficiency by avoiding on-chain transactions for every player move.
For a more detailed explanation and walkthrough of the project, please refer to the following resources:
- Video Explanation: Watch this short video to get an overview of the project and see it in action.
- Presentation Slides: Access the slides used in the video for more detailed information and step-by-step instructions.
Before you begin, ensure the following tools are installed on your system:
- Yarn: This project relies on Yarn for dependency installation because it provides better reliability and performance compared to npm/npx for this specific workflow.
- Cargo: The Rust package manager, required for compiling Rust contracts and running the node.
- Node.js: Version 18 or higher is required for compatibility with the development tools used in this project.
Follow these steps to install dependencies and set up your local environment:
-
Install project dependencies:
yarn install
Note: It's crucial to use Yarn for the installation to ensure proper dependencies are installed. Subsequent commands can be executed using npm/npx.
-
Start the Phala node:
npx devphase stack run --save-logs
Keep this running in one terminal window.
-
In a new terminal window, set up the Phala stack:
npx devphase stack setup -m 3
Note: This process might take longer than usual.
-
Compile the smart contracts:
npx devphase contract compile -c oh_my_chess
-
Deploy the Phat contract on the local network:
cd deploy && npx ts-node deploy_contract.ts --mongo_atlas_url <MONGO_ATLAS_URL> --mongo_atlas_api_key <MONGO_ATLAS_KEY>
Replace
<MONGO_ATLAS_URL>
and<MONGO_ATLAS_KEY>
with the right values of your instance.This command will deploy the Phat contract and return its address, denoted as
<PHAT_CONTRACT_ADDRESS>
. -
Run frontend in local machine:
6.1. Populate file
.env
at root level with:NEXT_PUBLIC_PHAT_CONTRACT_OH_MY_CHESS=<PHAT_CONTRACT_ADDRESS>
6.2 Run at root level
docker-compose up --build
You can now access the frontend at localhost:3000
Important: Interact with the Phat contract using scripts, as the contract methods require parameters.
For more details about the Phala Network, visit the official website.
For documentation regarding the Devphase CLI, refer to the Devphase Documentation.