Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
qbzzt committed Jan 27, 2024
1 parent 2e8e58e commit be89546
Showing 1 changed file with 47 additions and 46 deletions.
93 changes: 47 additions & 46 deletions docs/pages/guides/extending-world/add-table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,64 +14,65 @@ In contrast [to the Hello, World tutorial](/guides/hello-world/add-table), here

## Create the new table code

1. Create a new package.
This step is necessary because if we modify the `contracts` package the `pnpm dev` process detects the changes and if needed redeploys the `World`, which is not the behavior we want here.
1. Create a new package.
This step is necessary because if we modify the `contracts` package the `pnpm dev` process detects the changes and if needed redeploys the `World`, which is not the behavior we want here.

```sh copy
cd packages
mkdir history
cd history
```
```sh copy
cd packages
mkdir history
cd history
```

1. Install the necessary modules in the new package.
1. Install the necessary modules in the new package.

```sh copy
cp ../contracts/package.json .
pnpm install
```
```sh copy
cp ../contracts/package.json .
pnpm install
```

1. Create a MUD configuration file, `history.config.ts`, with the new table's definition.

```ts filename="history.config.ts" copy
import { mudConfig } from "@latticexyz/world/register";

export default mudConfig({
tables: {
History: {
keySchema: {
counterValue: "uint32",
},
valueSchema: {
blockNumber: "uint256",
time: "uint256",
},
},
},
});
```
1. Create a MUD configuration file, `history.config.ts`, with the new table's definition.

<details>
<summary>Explanation</summary>
```ts filename="history.config.ts" copy
import { mudConfig } from "@latticexyz/world/register";

A MUD table has two schemas:
export default mudConfig({
tables: {
History: {
keySchema: {
counterValue: "uint32",
},
valueSchema: {
blockNumber: "uint256",
time: "uint256",
},
},
},
});
```

- `keySchema`, the key used to find entries
- `valueSchema`, the value in the entry
<details>

Each schema is represented as a structure with field names as keys, and the appropriate [Solidity data types](https://docs.soliditylang.org/en/latest/types.html) as their values.
Note that the data types in the key schema are limited to those that are fixed length such at `bytes<n>`.
You cannot use strings, arrays, etc.
<summary>Explanation</summary>

In this case, the counter value is represented as a 32 bit unsigned integer, because that is what `Counter` uses.
Block numbers and timestamps can be values up to `uint256`, so we'll use this type for these fields.
A MUD table has two schemas:

</details>
- `keySchema`, the key used to find entries
- `valueSchema`, the value in the entry

1. Run this command to generate the table library.
Each schema is represented as a structure with field names as keys, and the appropriate [Solidity data types](https://docs.soliditylang.org/en/latest/types.html) as their values.
Note that the data types in the key schema are limited to those that are fixed length such at `bytes<n>`.
You cannot use strings, arrays, etc.

```sh copy
pnpm mud tablegen --configPath history.config.ts
```
In this case, the counter value is represented as a 32 bit unsigned integer, because that is what `Counter` uses.
Block numbers and timestamps can be values up to `uint256`, so we'll use this type for these fields.

</details>

1. Run this command to generate the table library.

```sh copy
pnpm mud tablegen --configPath history.config.ts
```

## Deploy the new table

Expand Down

0 comments on commit be89546

Please sign in to comment.