Skip to content

Commit 7106953

Browse files
authored
fix(vite-plugin-mud): start block as number (#3555)
1 parent ebe1aea commit 7106953

6 files changed

Lines changed: 17 additions & 10 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"create-mud": patch
3+
"vite-plugin-mud": patch
4+
---
5+
6+
Fixed an issue with providing world deploy's start block to Vite app's env.

packages/vite-plugin-mud/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ Vite plugin for MUD projects.
44

55
This plugin will use your environment's `VITE_CHAIN_ID` to load the world deploy from your `worlds.json` file and provide it to your app via new environment variables.
66

7-
| Variable | Type | Description |
8-
| ------------------------------- | --------------------- | ---------------------------------------------------------- |
9-
| `import.meta.env.CHAIN_ID` | `number` | The configured chain ID. |
10-
| `import.meta.env.WORLD_ADDRESS` | `Hex \| undefined` | The world contract address (if available). |
11-
| `import.meta.env.START_BLOCK` | `bigint \| undefined` | The block number the world was deployed at (if available). |
7+
| Variable | Type | Description |
8+
| ------------------------------- | --------------------- | ---------------------------------------------------- |
9+
| `import.meta.env.CHAIN_ID` | `number` | The configured chain ID. |
10+
| `import.meta.env.WORLD_ADDRESS` | `Hex \| undefined` | The world contract address (if available). |
11+
| `import.meta.env.START_BLOCK` | `number \| undefined` | The block number of the world deploy (if available). |
1212

1313
## Installation
1414

packages/vite-plugin-mud/env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
interface ImportMetaEnv {
22
readonly CHAIN_ID: number;
33
readonly WORLD_ADDRESS: `0x${string}` | undefined;
4-
readonly START_BLOCK: bigint | undefined;
4+
readonly START_BLOCK: number | undefined;
55
}

packages/vite-plugin-mud/src/plugin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function mud(opts: { worldsFile: string }): Plugin {
1515
const chainId = Number(env.VITE_CHAIN_ID) || 31337;
1616

1717
config.define ??= {};
18-
config.define["import.meta.env.CHAIN_ID"] = chainId;
18+
config.define["import.meta.env.CHAIN_ID"] = JSON.stringify(chainId);
1919

2020
if (!(await isReadable(worldsFile))) {
2121
console.log("no worlds file");
@@ -29,7 +29,8 @@ export function mud(opts: { worldsFile: string }): Plugin {
2929
const world = worlds[chainId];
3030
if (world) {
3131
config.define["import.meta.env.WORLD_ADDRESS"] = JSON.stringify(world.address);
32-
config.define["import.meta.env.START_BLOCK"] = world.blockNumber != null ? `${world.blockNumber}n` : undefined;
32+
config.define["import.meta.env.START_BLOCK"] =
33+
world.blockNumber != null ? JSON.stringify(world.blockNumber) : undefined;
3334
} else {
3435
console.log("no world deploy for chain ID", chainId);
3536
}

templates/react-ecs/packages/client/src/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Chain, Hex } from "viem";
44

55
export const chainId = import.meta.env.CHAIN_ID;
66
export const worldAddress = import.meta.env.WORLD_ADDRESS;
7-
export const startBlock = import.meta.env.START_BLOCK;
7+
export const startBlock = BigInt(import.meta.env.START_BLOCK ?? 0n);
88

99
export const url = new URL(window.location.href);
1010

templates/react/packages/client/src/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Chain } from "viem";
44

55
export const chainId = import.meta.env.CHAIN_ID;
66
export const worldAddress = import.meta.env.WORLD_ADDRESS;
7-
export const startBlock = import.meta.env.START_BLOCK;
7+
export const startBlock = BigInt(import.meta.env.START_BLOCK ?? 0n);
88

99
export const url = new URL(window.location.href);
1010

0 commit comments

Comments
 (0)