Skip to content

Commit

Permalink
feat: move example project
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaa committed Jun 4, 2024
1 parent ff619ab commit c7e2559
Show file tree
Hide file tree
Showing 43 changed files with 1,864 additions and 2,813 deletions.
10 changes: 10 additions & 0 deletions examples/multiple-namespaces/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
]
}
1 change: 1 addition & 0 deletions examples/multiple-namespaces/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
9 changes: 9 additions & 0 deletions examples/multiple-namespaces/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Minimal MUD example project with multiple clients

This example project demonstrates how to use the MUD framework to create a simple on-chain application. It includes several client types that you can pick from to run the app or get inspiration from, all using the same underlying smart contracts.

## Getting started

1. Since this project uses local MUD dependencies, you need to prepare them first by running this command in the MUD root directory: `pnpm install && pnpm build`
2. To start the development environment of this project, run `pnpm dev` in the project root. This will start a local chain, deploy the contracts in `packages/contracts`, and start a development server for the client. By default the react client (`packages/client-react`) will be used. To use the vanilla client instead, run `pnpm dev:client-vanilla`.
3. Open [localhost:3000](http://localhost:3000) in your browser.
10 changes: 10 additions & 0 deletions examples/multiple-namespaces/mprocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
procs:
client:
cwd: packages/client
shell: pnpm run dev
contracts:
cwd: packages/contracts
shell: pnpm mud dev-contracts --rpc http://127.0.0.1:8545
anvil:
cwd: packages/contracts
shell: anvil --base-fee 0 --block-time 2
28 changes: 28 additions & 0 deletions examples/multiple-namespaces/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "mud-example-minimal",
"private": true,
"scripts": {
"build": "pnpm recursive run build",
"clean": "pnpm recursive run clean",
"dev": "mprocs 'pnpm run dev:contracts' 'pnpm run dev:client-react'",
"dev-with-phaser": "mprocs 'pnpm run dev:contracts' 'pnpm run dev:client-phaser'",
"dev-with-vanilla": "mprocs 'pnpm run dev:contracts' 'pnpm run dev:client-vanilla'",
"dev:client-phaser": "pnpm --filter 'client-phaser' run dev",
"dev:client-react": "pnpm --filter 'client-react' run dev",
"dev:client-vanilla": "pnpm --filter 'client-vanilla' run dev",
"dev:contracts": "pnpm --filter 'contracts' run dev",
"test": "pnpm recursive run test"
},
"devDependencies": {
"@latticexyz/cli": "link:../../packages/cli",
"@typescript-eslint/eslint-plugin": "7.1.1",
"@typescript-eslint/parser": "7.1.1",
"eslint": "8.57.0",
"mprocs": "^0.6.4",
"typescript": "5.4.2"
},
"engines": {
"node": "^18",
"pnpm": "^8 || ^9"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ bindings/
artifacts/
broadcast/

# Ignore all MUD deploy artifacts
deploys
worlds.json*
# Ignore MUD deploy artifacts
deploys/**/*.json
8 changes: 8 additions & 0 deletions examples/multiple-namespaces/packages/contracts/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"plugins": ["prettier-plugin-solidity"],
"printWidth": 120,
"semi": true,
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": true
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": "solhint:recommended",
"extends": ["solhint:recommended", "mud"],
"plugins": ["mud"],
"rules": {
"compiler-version": ["error", ">=0.8.0"],
"avoid-low-level-calls": "off",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ allow_paths = [
# pnpm symlinks to the project root's node_modules
"../../node_modules",
# we're also using linked mud packages from the monorepo
"../../../packages"
"../../../../packages"
]
extra_output_files = [
"abi",
Expand Down
14 changes: 14 additions & 0 deletions examples/multiple-namespaces/packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineWorld } from "@latticexyz/world";

export default defineWorld({
namespace: "game",
tables: {
Health: {
schema: {
player: "address",
value: "uint256",
},
key: ["player"],
},
},
});
37 changes: 37 additions & 0 deletions examples/multiple-namespaces/packages/contracts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "contracts",
"version": "0.0.0",
"private": true,
"license": "MIT",
"scripts": {
"build": "mud build",
"clean": "forge clean && rimraf src/codegen",
"deploy:local": "mud deploy",
"dev": "mud dev-contracts",
"faucet": "DEBUG=mud:faucet faucet-server",
"lint": "pnpm run prettier && pnpm run solhint",
"prettier": "prettier --write 'src/**/*.sol'",
"solhint": "solhint --config ./.solhint.json 'src/**/*.sol' --fix",
"test": "mud test"
},
"devDependencies": {
"@latticexyz/cli": "link:../../../../packages/cli",
"@latticexyz/faucet": "link:../../../../packages/faucet",
"@latticexyz/schema-type": "link:../../../../packages/schema-type",
"@latticexyz/store": "link:../../../../packages/store",
"@latticexyz/world": "link:../../../../packages/world",
"@latticexyz/world-modules": "link:../../../../packages/world-modules",
"@solidstate/contracts": "^0.0.52",
"@types/node": "^18.15.11",
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
"forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1",
"prettier": "3.2.5",
"prettier-plugin-solidity": "1.3.1",
"rimraf": "^3.0.2",
"solhint": "^3.4.1",
"solhint-config-mud": "file:../../../../packages/solhint-config-mud",
"solhint-plugin-mud": "file:../../../../packages/solhint-plugin-mud",
"ts-node": "^10.9.1",
"typescript": "5.4.2"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

interface IChatNamespacedSystem {
function namespace__sendMessage(string memory message) external;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;
import { System } from "@latticexyz/world/src/System.sol";
import { Health } from "../codegen/tables/Health.sol";

contract HealSystem is System {
function heal(address player) public {
Health.set(player, Health.get(player) + 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import "forge-std/Test.sol";
import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";

import { IWorld } from "../src/codegen/world/IWorld.sol";
import { Health } from "../src/codegen/index.sol";

contract HealthTest is MudTest {
function testHealth(address player) public {
// Expect health to be 0 initially.
uint256 health = Health.get(player);
assertEq(health, 0);

// Expect the counter to be 1 after healing.
IWorld(worldAddress).game__heal(player);
health = Health.get(player);
assertEq(health, 1);
}
}
3 changes: 3 additions & 0 deletions examples/multiple-namespaces/packages/contracts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../../tsconfig.json"
}
9 changes: 9 additions & 0 deletions examples/multiple-namespaces/packages/contracts/worlds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"4242": {
"address": "0xb51cE08442de2aB60f327566db833eed15B47b60",
"blockNumber": 21817970
},
"31337": {
"address": "0x6e9474e9c83676b9a71133ff96db43e7aa0a4342"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const worlds: Partial<Record<string, { address: `0x${string}`; blockNumber?: number }>>;
export default worlds;
Loading

0 comments on commit c7e2559

Please sign in to comment.