MUD config
Certain CLI commands, such as mud tablegen
and mud worldgen
require the MUD configuration file.
This file needs to be named mud.config.ts
and be in the same folder as your foundry.toml
file.
The config is used to define:
- The tables in your project in the
tables
object of your configuration. - The namespace that systems and tables will be deployed in.
- The
System
s in your project. By default, the deployer will find all Solidity matching*System.sol
(so any file ending inSystem.sol
, in any folder) and deploy them as publicSystem
. If you want greater control over your systems (to change their public access or their name), you can use thesystems
object in the config. - The modules that will be installed in the
World
.
The is an example of a World
config:
import { mudConfig } from "@latticexyz/world/register";
import { resolveTableId } from "@latticexyz/config";
export default mudConfig({
excludeSystems: ["System3", "System2"],
worldContractName: "CustomWorld",
namespace: "mud",
systems: {
IncrementSystem: {
name: "increment",
openAccess: true,
},
},
tables: {
CounterTable: {
valueSchema: {
value: "uint32",
},
},
},
deploysDirectory: "./mud-deploys",
modules: [
{
name: "KeysWithValueModule",
root: true,
args: [resolveTableId("CounterTable")],
},
],
});
Global configuration keys
The global configuration keys are all optional.
-
namespace
: astring
: which namespace to deploy the resources defined in the config into. The default value is the ROOT namespace. -
excludeSystems
: an array ofstring
: which systems to not deploy, even if their name ends with “System”. -
worldContractName
: astring
: the name of a contract in your project implementing theIWorld
interface. Useful if you want to modify the default World implementation, but potentially dangerous. -
deploysDirectory
astring
: which folder to put the deployment artifacts into after deployment. -
modules
an array of module definitions: each module definition has aname
,root
(optional), andargs
key.-
name
: Name of the module to install. The same module can be installed multiple times. This should be the name of the contract file without.sol
(eg: if the file is namedDopeModule.sol
, the name of the module isDopeModule
) -
root
: whether to create aroot
module or not.root
modules have access to all tables and are not bound to namespace restrictions. -
args
: a list of arguments to be sent to theinstall
function of the module. In this array, you can use the functionresolveTableId
. This function will turn a table name from your config into its low-level ID in the World. It is useful to pass references of a table to a module.
-
-
systems
: a record of system definitions. The keys in the record are file names without the.sol
extension. For example, if your system is namedTestSystem.sol
, useTestSystem
as the key.The value is a record of system configuration properties:
-
fileSelector
(optional): astring
: the file selector for the system. -
openAccess
(optional, defaulttrue
): abool
: if set tofalse
, only the systems in the same namespace and the addresses or systems listed in theaccessList
array have access. -
accessList
(required if openAccess isfalse
): an array ofstring
. Each address in the array will be granted access to this system, allowing them to call it.
-
-
tables
: a record of tables. The keys in the record are table names. The value is a record of table properties (opens in a new tab).-
valueSchema
(record): The keys of this record are the field names of the value (which should start with a lowercase letter). The values are strings that contain the data types of the fields. Note that this is the sole required field, all the others are optional. -
keySchema
(record): The keys of this record are the field names of the key (which should start with a lowercase letter). The values are strings that contain the data types of the fields.The default value is:
{ "key": "bytes32" }
For a singleton table (one that contains a single row), use
{}
as the key schema. -
directory
(string): Directory in which to create the table. The default istables
, so by default tables are created insrc/codegen/tables
. -
tableIdArgument
(bool): Make methods accepttableId
argument instead of it being a hardcoded constant. The default isfalse
because you can achieve the same result usingStoreSwitch
. -
storeArgument
(bool): Include methods that accept a manualIStore
argument. The default istrue
. -
offchainOnly
: (bool): Table's information is available offchain (using events (opens in a new tab)), but don't store in onchain. These tables require a lot less gas. -
dataStruct
: (bool): Include a data struct (opens in a new tab) and methods for it. Default is false for 1-column tables; true for multi-column tables.Sample code for using a table library with
dataStruct
:// no data struct MyTable.set(keccak256("some.key"), 1, 12, "foo"); // data struct MyTable.set(keccak256("some.key"), { field1: 1, field2: 12, stringField: "foo" });
-