Dark Forest Game on Blockchain.
To run this project you will need to be on Node 14 OR Node 16.
- We use
npm
to manage packages. Runnpm ci
at the top level to automatically install all dependencies from subfolders. This will also run the monorepo'sprepare
script, which compiles things like TypeScript or Solidity code.
- Run
npm start --workspace eth
which starts the hardhat blockchain and deploys the game contracts. - Run
npm start --workspace client
to load the webclient. - Run
npm run watch
to start a typescript watcher to incrementally rebuild changed dependencies.
You can import the private key of one of the accounts hardhat node
created and funded, which are printed when you started the node such as:
Account #2: 0x3097403b64fe672467345bf159f4c9c5464bd89e (100 ETH)
Private Key: 0x67195c963ff445314e667112ab22f4a7404bad7f9746564eb409b9bb8c6aed32
If you wish to restart the game from scratch, you will need to clear local storage. To do this in Chrome or Brave Browser, open the inspector, navigate to the "Application" tab, click "Clear storage" on the left pane, and click "Clear site data" under the circle that appears in the main inspector panel. Then hard refresh the website.
Both localhost development and production contract addresses are stored in @dfdao/contracts
package. If you deploy contracts locally in a fresh node, this file will never change. If the file does change do not check in this file, as you probably have a hardhat node
process running in the background.
Production deploys must check in this file, but those will likely be done from CI and committed on a separate (non-development) branch.
The Dark Forest monorepo is managed using npm workspaces. To add a new project to the monorepo, you must add it to the workspaces
array inside the root package.json
.
Note: We use globs for anything in packages/
so you don't need to update the workspaces for a new package.
The packages/
directory is a place to store workspace packages that should be published to something like the https://npmjs.com registry, which allows players to build plugins, game clients, etc using the same code that Dark Forest itself uses.
To add a new package, create a new directory inside the packages/
directory. The package name for anything in packages/
should be prefixed with @dfdao/
to be published to our scope.
If you are modifying anything SNARK-related, you may be interested in rebuilding circuits / redoing setup. Run npm run circom:dev --workspace eth
or npm run circom:prod --workspace eth
respectively to rebuild the wasm
and zkey
files. Then npm run compile --workspace eth
as usual will build and refresh the Verifier.sol
.
To run a local copy of thegraph make sure docker is installed and running, npm start --workspace eth -- --subgraph df
OR if you already have your contracts deployed and running run npm run subgraph:deploy:dev --workspace eth
and find your local hosted explorer at http://localhost:8000/subgraphs/name/df