create-mud 2.0.12 → 2.0.13-account-kit-817df9903
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/templates/phaser/packages/art/package.json +1 -2
- package/dist/templates/phaser/packages/art/scripts/export-tiled-types.ts +3 -2
- package/dist/templates/react/packages/client/package.json +5 -1
- package/dist/templates/react/packages/client/src/App.tsx +80 -73
- package/dist/templates/react/packages/client/src/index.tsx +61 -18
- package/dist/templates/react/packages/client/src/mud/createSystemCalls.ts +30 -34
- package/dist/templates/react/packages/client/src/mud/getNetworkConfig.ts +3 -2
- package/dist/templates/react/packages/client/src/mud/setup.ts +0 -4
- package/dist/templates/react/packages/client/src/mud/setupNetwork.ts +4 -37
- package/dist/templates/react/packages/client/src/mud/supportedChains.ts +1 -1
- package/dist/templates/react/packages/client/src/polyfills.ts +6 -0
- package/dist/templates/react/packages/contracts/mud.config.ts +7 -0
- package/dist/templates/react/packages/contracts/worlds.json +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var t=require("create-create-app"),s=require("path");var e={name:"create-mud",version:"2.0.
|
|
2
|
+
var t=require("create-create-app"),s=require("path");var e={name:"create-mud",version:"2.0.13-account-kit-817df9903",description:"Create a new MUD project",license:"MIT",author:"Lattice <mud@lattice.xyz>",bin:"dist/cli.js",files:["dist"],scripts:{build:"pnpm run build:js","build:js":"tsup && ./scripts/copy-templates.sh",clean:"pnpm run clean:js","clean:js":"rimraf dist",dev:"tsup --watch",prepublishOnly:"npm run clean && npm run build",test:"pnpm run test:vanilla && pnpm run test:react && pnpm run test:react-ecs && pnpm run test:phaser && pnpm run test:threejs","test:ci":"pnpm run test","test:phaser":"dist/cli.js test-project --template phaser && rimraf test-project","test:react":"dist/cli.js test-project --template react && rimraf test-project","test:react-ecs":"dist/cli.js test-project --template react-ecs && rimraf test-project","test:threejs":"dist/cli.js test-project --template threejs && rimraf test-project","test:vanilla":"dist/cli.js test-project --template vanilla && rimraf test-project"},dependencies:{"create-create-app":"git+https://github.com/holic/create-create-app#74376c59b48a04aabbe94d9cacfe9cb1cecccd63"},devDependencies:{"@types/node":"^18.15.11",tsup:"^6.7.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"}};var c=(0,s.resolve)(__dirname,"..","dist","templates");(0,t.create)("create-mud",{templateRoot:c,defaultTemplate:"vanilla",defaultPackageManager:"pnpm",promptForDescription:!1,promptForAuthor:!1,promptForEmail:!1,promptForLicense:!1,promptForTemplate:!0,caveat:({answers:r,packageManager:a})=>`Done! Play in the MUD with \`cd ${r.name}\` and \`${a} run dev\``,extra:{"mud-version":{type:"input",describe:"The version of MUD packages to use, defaults to latest",default:e.version}}});
|
|
@@ -12,12 +12,11 @@
|
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@mapeditor/tiled-api": "^1.8.2",
|
|
14
14
|
"@types/ejs": "^3.1.1",
|
|
15
|
-
"@types/glob": "^7.2.0",
|
|
16
15
|
"@types/node": "^18.0.3",
|
|
17
16
|
"ejs": "^3.1.10",
|
|
18
17
|
"free-tex-packer-cli": "^0.3.0",
|
|
19
18
|
"free-tex-packer-core": "^0.3.4",
|
|
20
|
-
"glob": "^
|
|
19
|
+
"glob": "^10.4.2",
|
|
21
20
|
"optimist": "^0.6.1",
|
|
22
21
|
"ts-node": "^10.8.2",
|
|
23
22
|
"typescript": "5.4.2",
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import xlmJs from "xml-js";
|
|
2
2
|
import fs from "fs";
|
|
3
|
-
import
|
|
3
|
+
import { globSync } from "glob";
|
|
4
4
|
import ejs from "ejs";
|
|
5
5
|
import path from "path";
|
|
6
6
|
|
|
7
|
-
const tilemaps =
|
|
7
|
+
const tilemaps = globSync("./tilesets/*.tsx").sort();
|
|
8
|
+
|
|
8
9
|
enum PropertyName {
|
|
9
10
|
Name = "name",
|
|
10
11
|
Frame = "frame",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"test": "tsc --noEmit"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
+
"@latticexyz/account-kit": "{{mud-version}}",
|
|
14
15
|
"@latticexyz/common": "{{mud-version}}",
|
|
15
16
|
"@latticexyz/dev-tools": "{{mud-version}}",
|
|
16
17
|
"@latticexyz/react": "{{mud-version}}",
|
|
@@ -18,11 +19,14 @@
|
|
|
18
19
|
"@latticexyz/store-sync": "{{mud-version}}",
|
|
19
20
|
"@latticexyz/utils": "{{mud-version}}",
|
|
20
21
|
"@latticexyz/world": "{{mud-version}}",
|
|
22
|
+
"@rainbow-me/rainbowkit": "^2.0.2",
|
|
23
|
+
"@tanstack/react-query": "^5.28.8",
|
|
21
24
|
"contracts": "workspace:*",
|
|
22
25
|
"react": "^18.2.0",
|
|
23
26
|
"react-dom": "^18.2.0",
|
|
24
27
|
"rxjs": "7.5.5",
|
|
25
|
-
"viem": "2.9.20"
|
|
28
|
+
"viem": "2.9.20",
|
|
29
|
+
"wagmi": "^2.8.0"
|
|
26
30
|
},
|
|
27
31
|
"devDependencies": {
|
|
28
32
|
"@types/react": "18.2.22",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useMUD } from "./MUDContext";
|
|
2
|
+
import { AccountButton, useAppAccountClient } from "@latticexyz/account-kit";
|
|
2
3
|
|
|
3
4
|
const styleUnset = { all: "unset" } as const;
|
|
4
5
|
|
|
@@ -7,6 +8,7 @@ export const App = () => {
|
|
|
7
8
|
network: { tables, useStore },
|
|
8
9
|
systemCalls: { addTask, toggleTask, deleteTask },
|
|
9
10
|
} = useMUD();
|
|
11
|
+
const appAccountClient = useAppAccountClient();
|
|
10
12
|
|
|
11
13
|
const tasks = useStore((state) => {
|
|
12
14
|
const records = Object.values(state.getRecords(tables.Tasks));
|
|
@@ -16,90 +18,95 @@ export const App = () => {
|
|
|
16
18
|
|
|
17
19
|
return (
|
|
18
20
|
<>
|
|
19
|
-
<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
<AccountButton />
|
|
22
|
+
<br />
|
|
23
|
+
<br />
|
|
24
|
+
{appAccountClient ? (
|
|
25
|
+
<table>
|
|
26
|
+
<tbody>
|
|
27
|
+
{tasks.map((task) => (
|
|
28
|
+
<tr key={task.id}>
|
|
29
|
+
<td align="right">
|
|
30
|
+
<input
|
|
31
|
+
type="checkbox"
|
|
32
|
+
checked={task.value.completedAt > 0n}
|
|
33
|
+
title={task.value.completedAt === 0n ? "Mark task as completed" : "Mark task as incomplete"}
|
|
34
|
+
onChange={async (event) => {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
const checkbox = event.currentTarget;
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
checkbox.disabled = true;
|
|
39
|
+
try {
|
|
40
|
+
await toggleTask(appAccountClient, task.key.id);
|
|
41
|
+
} finally {
|
|
42
|
+
checkbox.disabled = false;
|
|
43
|
+
}
|
|
44
|
+
}}
|
|
45
|
+
/>
|
|
46
|
+
</td>
|
|
47
|
+
<td>{task.value.completedAt > 0n ? <s>{task.value.description}</s> : <>{task.value.description}</>}</td>
|
|
48
|
+
<td align="right">
|
|
49
|
+
<button
|
|
50
|
+
type="button"
|
|
51
|
+
title="Delete task"
|
|
52
|
+
style={styleUnset}
|
|
53
|
+
onClick={async (event) => {
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
if (!window.confirm("Are you sure you want to delete this task?")) return;
|
|
56
|
+
|
|
57
|
+
const button = event.currentTarget;
|
|
58
|
+
button.disabled = true;
|
|
59
|
+
try {
|
|
60
|
+
await deleteTask(appAccountClient, task.key.id);
|
|
61
|
+
} finally {
|
|
62
|
+
button.disabled = false;
|
|
63
|
+
}
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
×
|
|
67
|
+
</button>
|
|
68
|
+
</td>
|
|
69
|
+
</tr>
|
|
70
|
+
))}
|
|
71
|
+
</tbody>
|
|
72
|
+
<tfoot>
|
|
73
|
+
<tr>
|
|
74
|
+
<td>
|
|
75
|
+
<input type="checkbox" disabled />
|
|
40
76
|
</td>
|
|
41
|
-
<td
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type="button"
|
|
45
|
-
title="Delete task"
|
|
46
|
-
style={styleUnset}
|
|
47
|
-
onClick={async (event) => {
|
|
77
|
+
<td colSpan={2}>
|
|
78
|
+
<form
|
|
79
|
+
onSubmit={async (event) => {
|
|
48
80
|
event.preventDefault();
|
|
49
|
-
|
|
81
|
+
const form = event.currentTarget;
|
|
82
|
+
const fieldset = form.querySelector("fieldset");
|
|
83
|
+
if (!(fieldset instanceof HTMLFieldSetElement)) return;
|
|
84
|
+
|
|
85
|
+
const formData = new FormData(form);
|
|
86
|
+
const desc = formData.get("description");
|
|
87
|
+
if (typeof desc !== "string") return;
|
|
50
88
|
|
|
51
|
-
|
|
52
|
-
button.disabled = true;
|
|
89
|
+
fieldset.disabled = true;
|
|
53
90
|
try {
|
|
54
|
-
await
|
|
91
|
+
await addTask(appAccountClient, desc);
|
|
92
|
+
form.reset();
|
|
55
93
|
} finally {
|
|
56
|
-
|
|
94
|
+
fieldset.disabled = false;
|
|
57
95
|
}
|
|
58
96
|
}}
|
|
59
97
|
>
|
|
60
|
-
|
|
61
|
-
|
|
98
|
+
<fieldset style={styleUnset}>
|
|
99
|
+
<input type="text" name="description" />{" "}
|
|
100
|
+
<button type="submit" title="Add task">
|
|
101
|
+
Add
|
|
102
|
+
</button>
|
|
103
|
+
</fieldset>
|
|
104
|
+
</form>
|
|
62
105
|
</td>
|
|
63
106
|
</tr>
|
|
64
|
-
|
|
65
|
-
</
|
|
66
|
-
|
|
67
|
-
<tr>
|
|
68
|
-
<td>
|
|
69
|
-
<input type="checkbox" disabled />
|
|
70
|
-
</td>
|
|
71
|
-
<td colSpan={2}>
|
|
72
|
-
<form
|
|
73
|
-
onSubmit={async (event) => {
|
|
74
|
-
event.preventDefault();
|
|
75
|
-
const form = event.currentTarget;
|
|
76
|
-
const fieldset = form.querySelector("fieldset");
|
|
77
|
-
if (!(fieldset instanceof HTMLFieldSetElement)) return;
|
|
78
|
-
|
|
79
|
-
const formData = new FormData(form);
|
|
80
|
-
const desc = formData.get("description");
|
|
81
|
-
if (typeof desc !== "string") return;
|
|
82
|
-
|
|
83
|
-
fieldset.disabled = true;
|
|
84
|
-
try {
|
|
85
|
-
await addTask(desc);
|
|
86
|
-
form.reset();
|
|
87
|
-
} finally {
|
|
88
|
-
fieldset.disabled = false;
|
|
89
|
-
}
|
|
90
|
-
}}
|
|
91
|
-
>
|
|
92
|
-
<fieldset style={styleUnset}>
|
|
93
|
-
<input type="text" name="description" />{" "}
|
|
94
|
-
<button type="submit" title="Add task">
|
|
95
|
-
Add
|
|
96
|
-
</button>
|
|
97
|
-
</fieldset>
|
|
98
|
-
</form>
|
|
99
|
-
</td>
|
|
100
|
-
</tr>
|
|
101
|
-
</tfoot>
|
|
102
|
-
</table>
|
|
107
|
+
</tfoot>
|
|
108
|
+
</table>
|
|
109
|
+
) : null}
|
|
103
110
|
</>
|
|
104
111
|
);
|
|
105
112
|
};
|
|
@@ -1,8 +1,43 @@
|
|
|
1
|
+
import "./polyfills";
|
|
2
|
+
import "@rainbow-me/rainbowkit/styles.css";
|
|
1
3
|
import ReactDOM from "react-dom/client";
|
|
2
4
|
import { App } from "./App";
|
|
3
5
|
import { setup } from "./mud/setup";
|
|
4
6
|
import { MUDProvider } from "./MUDContext";
|
|
5
|
-
import mudConfig from "contracts/mud.config";
|
|
7
|
+
// import mudConfig from "contracts/mud.config";
|
|
8
|
+
import { WagmiProvider, createConfig } from "wagmi";
|
|
9
|
+
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
|
|
10
|
+
import { supportedChains } from "./mud/supportedChains";
|
|
11
|
+
import { createClient, http } from "viem";
|
|
12
|
+
import { getNetworkConfig } from "./mud/getNetworkConfig";
|
|
13
|
+
import { RainbowKitProvider, lightTheme, midnightTheme } from "@rainbow-me/rainbowkit";
|
|
14
|
+
import { AccountKitProvider } from "@latticexyz/account-kit";
|
|
15
|
+
|
|
16
|
+
const queryClient = new QueryClient();
|
|
17
|
+
|
|
18
|
+
const wagmiConfig = createConfig({
|
|
19
|
+
chains: supportedChains,
|
|
20
|
+
client: ({ chain }) =>
|
|
21
|
+
createClient({
|
|
22
|
+
chain,
|
|
23
|
+
// We intentionally don't use fallback+webSocket here because if a chain's RPC config
|
|
24
|
+
// doesn't include a `webSocket` entry, it doesn't seem to fallback and instead just
|
|
25
|
+
// ~never makes any requests and all queries seem to sit idle.
|
|
26
|
+
transport: http(),
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const rainbowKitTheme = {
|
|
31
|
+
lightMode: lightTheme({ borderRadius: "none" }),
|
|
32
|
+
darkMode: midnightTheme({ borderRadius: "none" }),
|
|
33
|
+
} as const;
|
|
34
|
+
|
|
35
|
+
const networkConfig = getNetworkConfig();
|
|
36
|
+
const accountKitConfig = {
|
|
37
|
+
chainId: networkConfig.chain.id,
|
|
38
|
+
worldAddress: networkConfig.worldAddress,
|
|
39
|
+
erc4337: false,
|
|
40
|
+
} as const;
|
|
6
41
|
|
|
7
42
|
const rootElement = document.getElementById("react-root");
|
|
8
43
|
if (!rootElement) throw new Error("React root not found");
|
|
@@ -11,24 +46,32 @@ const root = ReactDOM.createRoot(rootElement);
|
|
|
11
46
|
// TODO: figure out if we actually want this to be async or if we should render something else in the meantime
|
|
12
47
|
setup().then(async (result) => {
|
|
13
48
|
root.render(
|
|
14
|
-
<
|
|
15
|
-
<
|
|
16
|
-
|
|
49
|
+
<WagmiProvider config={wagmiConfig}>
|
|
50
|
+
<QueryClientProvider client={queryClient}>
|
|
51
|
+
<RainbowKitProvider theme={rainbowKitTheme}>
|
|
52
|
+
<AccountKitProvider config={accountKitConfig}>
|
|
53
|
+
<MUDProvider value={result}>
|
|
54
|
+
<App />
|
|
55
|
+
</MUDProvider>
|
|
56
|
+
</AccountKitProvider>
|
|
57
|
+
</RainbowKitProvider>
|
|
58
|
+
</QueryClientProvider>
|
|
59
|
+
</WagmiProvider>,
|
|
17
60
|
);
|
|
18
61
|
|
|
19
62
|
// https://vitejs.dev/guide/env-and-mode.html
|
|
20
|
-
if (import.meta.env.DEV) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
63
|
+
// if (import.meta.env.DEV) {
|
|
64
|
+
// const { mount: mountDevTools } = await import("@latticexyz/dev-tools");
|
|
65
|
+
// mountDevTools({
|
|
66
|
+
// config: mudConfig,
|
|
67
|
+
// publicClient: result.network.publicClient,
|
|
68
|
+
// walletClient: result.network.walletClient,
|
|
69
|
+
// latestBlock$: result.network.latestBlock$,
|
|
70
|
+
// storedBlockLogs$: result.network.storedBlockLogs$,
|
|
71
|
+
// worldAddress: result.network.worldContract.address,
|
|
72
|
+
// worldAbi: result.network.worldContract.abi,
|
|
73
|
+
// write$: result.network.write$,
|
|
74
|
+
// useStore: result.network.useStore,
|
|
75
|
+
// });
|
|
76
|
+
// }
|
|
34
77
|
});
|
|
@@ -1,50 +1,46 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Create the system calls that the client can use to ask
|
|
3
|
-
* for changes in the World state (using the System contracts).
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
1
|
import { Hex } from "viem";
|
|
7
2
|
import { SetupNetworkResult } from "./setupNetwork";
|
|
3
|
+
import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
|
|
4
|
+
import { AppAccountClient } from "@latticexyz/account-kit";
|
|
8
5
|
|
|
9
6
|
export type SystemCalls = ReturnType<typeof createSystemCalls>;
|
|
10
7
|
|
|
11
|
-
export function createSystemCalls(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* - worldContract (which comes from getContract, see
|
|
20
|
-
* https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L63-L69).
|
|
21
|
-
*
|
|
22
|
-
* - waitForTransaction (which comes from syncToRecs, see
|
|
23
|
-
* https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83).
|
|
24
|
-
*
|
|
25
|
-
* - From the second parameter, which is a ClientComponent,
|
|
26
|
-
* we only care about Counter. This parameter comes to use
|
|
27
|
-
* through createClientComponents.ts, but it originates in
|
|
28
|
-
* syncToRecs
|
|
29
|
-
* (https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83).
|
|
30
|
-
*/
|
|
31
|
-
{ tables, useStore, worldContract, waitForTransaction }: SetupNetworkResult,
|
|
32
|
-
) {
|
|
33
|
-
const addTask = async (label: string) => {
|
|
34
|
-
const tx = await worldContract.write.app__addTask([label]);
|
|
8
|
+
export function createSystemCalls({ tables, useStore, waitForTransaction, worldAddress }: SetupNetworkResult) {
|
|
9
|
+
const addTask = async (client: AppAccountClient, label: string) => {
|
|
10
|
+
const tx = await client.writeContract({
|
|
11
|
+
address: worldAddress,
|
|
12
|
+
abi: IWorldAbi,
|
|
13
|
+
functionName: "app__addTask",
|
|
14
|
+
args: [label],
|
|
15
|
+
});
|
|
35
16
|
await waitForTransaction(tx);
|
|
36
17
|
};
|
|
37
18
|
|
|
38
|
-
const toggleTask = async (id: Hex) => {
|
|
19
|
+
const toggleTask = async (client: AppAccountClient, id: Hex) => {
|
|
39
20
|
const isComplete = (useStore.getState().getValue(tables.Tasks, { id })?.completedAt ?? 0n) > 0n;
|
|
40
21
|
const tx = isComplete
|
|
41
|
-
? await
|
|
42
|
-
|
|
22
|
+
? await client.writeContract({
|
|
23
|
+
address: worldAddress,
|
|
24
|
+
abi: IWorldAbi,
|
|
25
|
+
functionName: "app__resetTask",
|
|
26
|
+
args: [id],
|
|
27
|
+
})
|
|
28
|
+
: await client.writeContract({
|
|
29
|
+
address: worldAddress,
|
|
30
|
+
abi: IWorldAbi,
|
|
31
|
+
functionName: "app__completeTask",
|
|
32
|
+
args: [id],
|
|
33
|
+
});
|
|
43
34
|
await waitForTransaction(tx);
|
|
44
35
|
};
|
|
45
36
|
|
|
46
|
-
const deleteTask = async (id: Hex) => {
|
|
47
|
-
const tx = await
|
|
37
|
+
const deleteTask = async (client: AppAccountClient, id: Hex) => {
|
|
38
|
+
const tx = await client.writeContract({
|
|
39
|
+
address: worldAddress,
|
|
40
|
+
abi: IWorldAbi,
|
|
41
|
+
functionName: "app__deleteTask",
|
|
42
|
+
args: [id],
|
|
43
|
+
});
|
|
48
44
|
await waitForTransaction(tx);
|
|
49
45
|
};
|
|
50
46
|
|
|
@@ -21,8 +21,9 @@ import worlds from "contracts/worlds.json";
|
|
|
21
21
|
* The supported chains.
|
|
22
22
|
*/
|
|
23
23
|
import { supportedChains } from "./supportedChains";
|
|
24
|
+
import { Hex } from "viem";
|
|
24
25
|
|
|
25
|
-
export
|
|
26
|
+
export function getNetworkConfig() {
|
|
26
27
|
const params = new URLSearchParams(window.location.search);
|
|
27
28
|
|
|
28
29
|
/*
|
|
@@ -70,7 +71,7 @@ export async function getNetworkConfig() {
|
|
|
70
71
|
privateKey: getBurnerPrivateKey(),
|
|
71
72
|
chainId,
|
|
72
73
|
chain,
|
|
73
|
-
worldAddress,
|
|
74
|
+
worldAddress: worldAddress as Hex,
|
|
74
75
|
initialBlockNumber,
|
|
75
76
|
};
|
|
76
77
|
}
|
|
@@ -3,21 +3,10 @@
|
|
|
3
3
|
* (https://viem.sh/docs/getting-started.html).
|
|
4
4
|
* This line imports the functions we need from it.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
createPublicClient,
|
|
8
|
-
fallback,
|
|
9
|
-
webSocket,
|
|
10
|
-
http,
|
|
11
|
-
createWalletClient,
|
|
12
|
-
Hex,
|
|
13
|
-
ClientConfig,
|
|
14
|
-
getContract,
|
|
15
|
-
} from "viem";
|
|
6
|
+
import { createPublicClient, fallback, webSocket, http, Hex, ClientConfig } from "viem";
|
|
16
7
|
import { syncToZustand } from "@latticexyz/store-sync/zustand";
|
|
17
8
|
import { getNetworkConfig } from "./getNetworkConfig";
|
|
18
|
-
import
|
|
19
|
-
import { createBurnerAccount, transportObserver, ContractWrite } from "@latticexyz/common";
|
|
20
|
-
import { transactionQueue, writeObserver } from "@latticexyz/common/actions";
|
|
9
|
+
import { transportObserver, ContractWrite } from "@latticexyz/common";
|
|
21
10
|
import { Subject, share } from "rxjs";
|
|
22
11
|
|
|
23
12
|
/*
|
|
@@ -33,7 +22,7 @@ import mudConfig from "contracts/mud.config";
|
|
|
33
22
|
export type SetupNetworkResult = Awaited<ReturnType<typeof setupNetwork>>;
|
|
34
23
|
|
|
35
24
|
export async function setupNetwork() {
|
|
36
|
-
const networkConfig =
|
|
25
|
+
const networkConfig = getNetworkConfig();
|
|
37
26
|
|
|
38
27
|
/*
|
|
39
28
|
* Create a viem public (read only) client
|
|
@@ -53,27 +42,6 @@ export async function setupNetwork() {
|
|
|
53
42
|
*/
|
|
54
43
|
const write$ = new Subject<ContractWrite>();
|
|
55
44
|
|
|
56
|
-
/*
|
|
57
|
-
* Create a temporary wallet and a viem client for it
|
|
58
|
-
* (see https://viem.sh/docs/clients/wallet.html).
|
|
59
|
-
*/
|
|
60
|
-
const burnerAccount = createBurnerAccount(networkConfig.privateKey as Hex);
|
|
61
|
-
const burnerWalletClient = createWalletClient({
|
|
62
|
-
...clientOptions,
|
|
63
|
-
account: burnerAccount,
|
|
64
|
-
})
|
|
65
|
-
.extend(transactionQueue())
|
|
66
|
-
.extend(writeObserver({ onWrite: (write) => write$.next(write) }));
|
|
67
|
-
|
|
68
|
-
/*
|
|
69
|
-
* Create an object for communicating with the deployed World.
|
|
70
|
-
*/
|
|
71
|
-
const worldContract = getContract({
|
|
72
|
-
address: networkConfig.worldAddress as Hex,
|
|
73
|
-
abi: IWorldAbi,
|
|
74
|
-
client: { public: publicClient, wallet: burnerWalletClient },
|
|
75
|
-
});
|
|
76
|
-
|
|
77
45
|
/*
|
|
78
46
|
* Sync on-chain state into RECS and keeps our client in sync.
|
|
79
47
|
* Uses the MUD indexer if available, otherwise falls back
|
|
@@ -88,14 +56,13 @@ export async function setupNetwork() {
|
|
|
88
56
|
});
|
|
89
57
|
|
|
90
58
|
return {
|
|
59
|
+
...networkConfig,
|
|
91
60
|
tables,
|
|
92
61
|
useStore,
|
|
93
62
|
publicClient,
|
|
94
|
-
walletClient: burnerWalletClient,
|
|
95
63
|
latestBlock$,
|
|
96
64
|
storedBlockLogs$,
|
|
97
65
|
waitForTransaction,
|
|
98
|
-
worldContract,
|
|
99
66
|
write$: write$.asObservable().pipe(share()),
|
|
100
67
|
};
|
|
101
68
|
}
|
|
@@ -16,4 +16,4 @@ import { MUDChain, mudFoundry, redstone, garnet } from "@latticexyz/common/chain
|
|
|
16
16
|
* See https://mud.dev/tutorials/minimal/deploy#run-the-user-interface
|
|
17
17
|
* for instructions on how to add networks.
|
|
18
18
|
*/
|
|
19
|
-
export const supportedChains: MUDChain[] = [mudFoundry, redstone, garnet];
|
|
19
|
+
export const supportedChains: readonly [MUDChain, ...MUDChain[]] = [mudFoundry, redstone, garnet];
|