World
Modules

Modules

Modules are onchain installation scripts that create resources and their associated configuration when called by a World. This is somewhat similar to one of the use cases for foundry scripts (opens in a new tab), except that modules are deployed onchain and can be used by any World on the same chain.

Module installation

The easiest way to install modules is to edit the config file. At the top level you specify modules, a list of modules to install. Every module is a struct with three parameters:

  • artifactPath - relative path to the module's compiled JSON artifact (usually in out) or an import path if using a module from an npm package. This path is resolved using Node's module require API (opens in a new tab).
  • root - whether the module is to be installed with root namespace privileges. The default is false.
  • args - a list of arguments to give the module's install function. Each argument is a structure with two fields:

You can see an example of this method on the ERC-721 module page.

Installation by transaction

Modules can be installed using World.installModule(address moduleAddress, bytes memory initData) (opens in a new tab). When you do this, the World calls the module's install function with initData as the argument(s). Because this is a call, the module does not have any administrative permissions on the World.

Alternatively, the owner of the root namespace can install modules using World.installRootModule(address moduleAddress, bytes memory initData) (opens in a new tab). In this case, the World uses delegatecall and module has all the permissions of a System in the root namespace.

Writing modules

The common use for a module is to add functionality to a World. In most cases we expect that a module would:

  1. Create a namespace for the new functionality.
  2. Create the tables and Systems for the new functionality.
  3. Create any access permissions required (beyond the default, which is that a System has access to its own namespace).
  4. Either assign the ownership of the new namespace to an entity that would administer it (a user, a multisig, etc.) or burn it by assigning the namespace ownership to address(0).

Root modules run with the same permission as Systems in the root namespace, so they do not need to create a namespace for themselves. They can just create their own tables and Systems as needed.

For more information about writing modules see the detailed guide.

Sample modules

MUD comes with several modules you can use or inspect to help you write your own: