{"id":13453170,"url":"https://github.com/projectsophon/darkforest-local","last_synced_at":"2025-03-05T10:34:39.855Z","repository":{"id":38335683,"uuid":"385000201","full_name":"projectsophon/darkforest-local","owner":"projectsophon","description":"Run your own local game of Dark Forest","archived":false,"fork":false,"pushed_at":"2022-08-11T04:25:45.000Z","size":3511,"stargazers_count":82,"open_issues_count":5,"forks_count":100,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-28T20:37:49.444Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/projectsophon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-11T16:35:35.000Z","updated_at":"2024-07-21T06:37:54.000Z","dependencies_parsed_at":"2022-07-12T17:25:01.314Z","dependency_job_id":null,"html_url":"https://github.com/projectsophon/darkforest-local","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectsophon%2Fdarkforest-local","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectsophon%2Fdarkforest-local/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectsophon%2Fdarkforest-local/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectsophon%2Fdarkforest-local/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/projectsophon","download_url":"https://codeload.github.com/projectsophon/darkforest-local/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242011004,"owners_count":20057371,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T08:00:34.025Z","updated_at":"2025-03-05T10:34:39.812Z","avatar_url":"https://github.com/projectsophon.png","language":null,"funding_links":[],"categories":["Plugins"],"sub_categories":["Developers"],"readme":"# darkforest-local\n\nThe Dark Forest client deploy process is set up for players to easily fork the client and connect to the mainnet game, but that design decision currently makes it difficult to run a playable version of the game locally. This repository provides a setup for running a local game with just a few steps.\n\n## Builder's Guide\n\nFor a comprehensive tutorial on using this repository to make custom local games and deploy them, check out the [Builder's Guide](builders_guide.md).\n\n## How `darkforest-local` works\n\nThis repo uses [submodules](.gitmodules) to pair the [Dark Forest Ethereum backend](https://github.com/darkforest-eth/eth) with the [Dark Forest TypeScript frontend](https://github.com/darkforest-eth/client) so you can launch a local game.\n\nIt also uses Yarn, a package manager (like `npm`) that allows for multiple [workspaces](https://classic.yarnpkg.com/lang/en/docs/workspaces) to exist within a project.\n\nThe workspaces allows each [submodule](.gitmodules) to have their own packages and configuration. \nYarn places all of the packages for each submodule in the top level `node_modules/` folder.\n\n## Requirements\n* Install `node \u003e= 14` (You can consider using [nvm](https://github.com/nvm-sh/nvm))\n* Install [Yarn](https://classic.yarnpkg.com/en/docs/install)\n\n### Quickstart for running a local game\n1. Fork [darkforest-local](https://github.com/projectsophon/darkforest-local) to your GitHub account\n2. `git clone --recurse-submodules https://github.com/\u003cyour_name\u003e/darkforest-local.git`\n3. If you didn't clone with `--recurse-submodules` or already have a cloned version: `git submodule update --init --recursive --remote --merge`\n4. `yarn`\n5. `yarn start`\n\n### If you plan to make changes to `darkforest-local`\n1. Fork [darkforest-local](https://github.com/projectsophon/darkforest-local) to your GitHub account\n2. Fork [darkforest-eth/eth](https://github.com/darkforest-eth/eth) to your GitHub account\n3. Fork [darkforest-eth/client](https://github.com/darkforest-eth/client) to your GitHub account\n4. Fork [darkforest-eth/circuits](https://github.com/darkforest-eth/circuits) to your GitHub account\n5. Fork [darkforest-eth/packages](https://github.com/darkforest-eth/packages) to your GitHub account\n4. Clone your darkforest-local repo: `git clone https://github.com/\u003cyour_name\u003e/darkforest-local.git`\n5. Update the `.gitmodules` file to point to your new forks of `eth`, `client`, `circuits`, and `packages` \n    ex: \n    * `url = https://github.com/darkforest-eth/eth` =\u003e `url = https://github.com/cha0sg0d/eth`\n    * `url = https://github.com/darkforest-eth/client` =\u003e `url = https://github.com/cha0sg0d/client`\n    * `url = https://github.com/darkforest-eth/circuits` =\u003e `url = https://github.com/cha0sg0d/circuits`\n    * `url = https://github.com/darkforest-eth/packages` =\u003e `url = https://github.com/cha0sg0d/packages`\n6. Fetch the code from the submodules\n    * `git submodule update --init --recursive`   \n7. Add new branches for developing:\n    - The `darkforest-local` monorepo detaches the submodules from their current HEADs. If you want to save your changes (for example, if you're testing an new contract in `eth`), you'll need to make a new branch in these submodules.\n    1. `cd eth`\n        1. `git checkout -b \u003cnew_name\u003e`\n    2. `cd client`\n        1. `git checkout -b \u003cnew_name\u003e`\n    3. `cd circuits`\n        1. `git checkout -b \u003cnew_name\u003e`\n    4. `cd packages`\n        1. `git checkout -b \u003cnew_name\u003e`\n7. Install packages and dependencies\n    * `yarn`\n8. Start a game\n    * `yarn start`\n\n            \n## Run a local game\n\n- Running `yarn start`, will 1) start a local node, 2) deploy the contracts, and 3) run the local client in dev mode\n- When finished, the process should pop up your browser to the game client at http://localhost:8081/\n\n- Here are 3 private keys with 100 ETH each to use in the game:\n    1. `0x044C7963E9A89D4F8B64AB23E02E97B2E00DD57FCB60F316AC69B77135003AEF`\n    2. `0x523170AAE57904F24FFE1F61B7E4FF9E9A0CE7557987C2FC034EACB1C267B4AE`\n    3. `0x67195c963ff445314e667112ab22f4a7404bad7f9746564eb409b9bb8c6aed32`\n\n\n## Static deployment of Dark Forest (no webserver)\n\nIf you want to deploy the contracts (with whatever modifications you want) to mainnet, and client\ncode (with whatever modifications you want), you can follow these instructions. The reasons you\nmight want to do this could be one of:\n\n- You want to run a community round of Dark Forest\n- You want to run a multiplayer round with some friends\n- etc.\n\nDeploying to production is quite similar to deploying a local version of the game, but I'm going to\nwalk through the steps explicitly here.\n\n### Step 1: Deploy contracts\n\nUnlike in development mode, in production mode you will need to create a `.env` file in both the\n`client/` and `eth/` submodules. You can find the set of environment variables you will need to\npopulate those `.env` files with in their adjacent `.env.example` files.\n\n\u003e **Danger!** The `.env` files ARE in the respective `.gitignore`s of the aforementioned submodules,\n\u003e however you should also manually make sure that they don't end up checked into your repository.\n\nTo randomly generate a new deployer private key and mnemonic for `eth/.env`, run \n```bash\nyarn workspace eth hardhat wallet:new\n```\nYou should see something like this:\n\n![yarn workspace eth hardhat wallet:new](img/new_key.png)\n\n\nTo deploy the contracts, you will need to run the following command:\n\n```bash\nyarn workspace eth hardhat:prod deploy\n```\n\nYou should see something like this:\n\n![yarn workspace eth hardhat:prod deploy](img/hardhat_prod_deploy.png)\n\nTo find out more information about the `contracts` submodule, you can look here:\n[https://github.com/darkforest-eth/eth](https://github.com/darkforest-eth/eth).\n\n### Step 2: Deploy client website\n\nTo deploy the website interface, you may either self-host, or use the same infra that we use -\n[Netlify](https://www.netlify.com/). This is a simple option, and free for up to some amount of\ngigabytes of bandwidth per month, which has often been enough for us.\n\nTo use Netlify:\n\n- Make a new [Netlify account](https://app.netlify.com/signup) using your Github profile.\n- [Import](https://app.netlify.com/start) your forked **darkforest-local** repo as a new Netlify site.\n\n    - During Step 3 of the import (Site settings, and deploy!):\n        - Build command: `yarn workspace client build`\n        - Publish directory: `client/dist`\n\n    Your initial settings should look like this:\n\n    ![netlify_settings](img/netlify_import.png)  \n\n    *Importing from Github will automatically trigger an initial build by Netlify, which will take ~5 min.*\n\n- Install the Netlify CLI\n    - `npm install netlify-cli -g`\n- Login to your account\n    - `netlify login`\n- Connect to your app\n    - `netlify link`\n    \n    ![Netlify link](img/link.png)\n    \n- Choose *Enter a site ID*\n    \n    ![Site ID](img/site_id.png)\n    \n- Input the id that you find by clicking on your new site on Netlify. In this example, the id is `jolly-hermann-3947ca`\n- Now that your site is linked, you can deploy to Netlify from the CLI.\n    - `yarn deploy:client:prod`\n    - If successful, you will see something like this.\n        \n        ![deploy_success](img/netlify_deploy.png)\n    - By default, all future changes to the branch you specified in the settings will result in an automatic deploy (in this case `master`). \n    - You can still choose to deploy manually (via `yarn deploy:client:prod`).\n    - Additionally, if you want to stop auto-publishing via git updates, see this image:\n        ![stop_auto_publishing](img/stop_auto_publishing.png)\n\n### Step 3: Allow player addresses\n\nThe default implementation of Dark Forest ships with a [whitelist\ncontract](https://github.com/darkforest-eth/eth/blob/master/contracts/Whitelist.sol). When we\ndeployed the contracts in Step 1, amongst them was this whitelist contract. A 'static' deployment of\nDark Forest (no web server) isn't capable of submitting a whitelisting transaction on behalf of the\nuser (which lets a given burner address into the game and drips it a fraction of an xDAI).\n\nThis means that if you want to let players into your game, you must first collect their\naddresses.\n\nIf you want to generate a burner wallet on the CLI for testing, follow the same steps from [Step 1](#step-1-deploy-contracts):\n\n```bash\nyarn workspace eth hardhat:dev wallet:new\n```\n\n\nOnce you collect the addresses of the people you want to let into your world, you can register them\nindividually via the following command\n\n```bash\nyarn workspace eth hardhat:prod whitelist:register --address $BURNER_WALLET_ADDRESS\n# where $BURNER_WALLET_ADDRESS is the network address of the player you want to allow to play in\n# your deployment of the game.\n```\n\nIf everything worked properly, you should be able to log in:\n\n![log in](img/log_in.png)\n\nThen, once you've found a home planet, you should be able to enter the game!\n\n![enter game](img/enter_game.png)\n\n### Step 4: Play your game\n\n- Now go the URL given by Netlify → something like [https://jolly-hermann-3947ca.netlify.app/](https://jolly-hermann-3947ca.netlify.app/) and test out your game! Login with one of the private keys for the addresses that were whitelisted. Make some moves and test that everything works as expected.\n\n## Update to latest Dark Forest code\n\nIf theres been new Dark Forest updates released and we haven't yet updated this repo yet, it is possible you can get away with updating yourself by running `git submodule update --remote --merge` and remember to run `yarn` again.\n\n## For maintainers of the repo updating to latest Dark Forest code\n\n- [Update the submodules](#update-to-latest-dark-forest-code).\n- Replace the root `yarn.lock` with the `yarn.lock` from `eth/` or `client/`\n- Run `yarn`.\n- Finally add all changes, commit, and PR.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectsophon%2Fdarkforest-local","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprojectsophon%2Fdarkforest-local","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectsophon%2Fdarkforest-local/lists"}