Source

Primodium Source

The Primodium source code is available across two repositories:

All Primodium contracts conform to the open MUD standard (opens in a new tab) for large-scale Ethereum applications, details of which can be found in the Primodium contracts guide and the MUD documentation (opens in a new tab).

In our development process, we also added supplements to the standard that improved Primodium's internal design and developer experience. Our commitment to open source means that these improvements will be shared as development progresses, such as Primodium world extensions and prototype generation scripts.

The initial sections describe deploying your own Primodium instance, followed by World Extension development resources.

Installation

The @primodiumxyz/primodium (opens in a new tab) monorepo contains the entire stack for running Primodium, including the React client and Phaser game, the local postgres indexer (that can be deployed to a cloud provider as well) and all the contracts.

Prerequisites

There are a few CLI tools to install to be compatible with the entire monorepo.

Setup

Clone this repository:

git clone https://github.com/primodiumxyz/primodium.git

Install all dependencies:

pnpm i

Environment

Create a .env file in the root of the project, and follow the instructions in the .env.example file to set the environment variables.

cp .env.example .env

You will also need to write the deployer's private key in some environment variable in the contracts package.

# The default anvil private key
echo "PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" >> ./packages/contracts/.env

Structure

examples - "Examples and boilerplate for adding extensions to the game"
packages - "Components of the entire stack for running Primodium"
├── assets - "All ingame assets and atlas"
├── client - "React client that integrates other components and supercharges with a browser UI"
├── contracts - "MUD contracts, configuration and infrastructure—basically the whole state and conditions of the game"
├── core - "Core logic, systems, hooks and utilities for the client"
├── engine - "Game engine for managing Phaser scenes and user inputs"
└── game - "Core Phaser infrastructure for the game; objects, scenes, systems, input controls, etc."

Development

Running the game

The whole stack can be run with the following command:

pnpm dev

This will run a series of scripts each in a separate window, including the client, the development chain (on which contracts get deployed) and the local postgres indexer.

NOTE: When running the indexer locally, docker network and volumes properly clear only on rerun of pnpm dev:indexer. If you would like to manually free these resources run pnpm clean:indexer.

Building

You can build the entire monorepo with the following command:

pnpm build

This will build the client and core packages, and compile the contracts as well as generate the ABIs and TypeScript bindings.

Testing

To run the tests for every package, run the following:

pnpm test

Or if you want to run the tests for a specific package, navigate to that package directory and run the same command.

Deployment

To deploy the contracts on a specific chain, follow these steps:

  1. Update .env (opens in a new tab):
  2. Add the private key of the deployer to packages/contracts/.env (opens in a new tab):
    echo "PRIVATE_KEY=<your-private-key>" >> ./packages/contracts/.env
  3. Deploy the contracts:
    pnpm deploy:<chain_id> # if the command doesn't exist, create it in both `packages/contracts/package.json` and `package.json`

World Extension Resources

For developers creating world extensions, the following resources are available:

Contract Tables:

Contract Systems:

Contract Prototype Table Data:

Contract Prototype Generation Scripts: