Primodium Source
The Primodium source code is available across two repositories:
@primodiumxyz/primodium
(opens in a new tab): Full source code with both Ethereum smart contracts and TypeScript frontend@primodiumxyz/contracts
(opens in a new tab): Source of generated smart contract interfaces for world extension developers
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.
- node (opens in a new tab) v20.x - Tested with node v20.18.2.
- You can use nvm (opens in a new tab) to install and manage multiple versions of node.
- pnpm (opens in a new tab) v8.x - Tested with pnpm v8.15.9.
- Foundry (opens in a new tab) - This will get installer during the "prepare" script.
- Docker (opens in a new tab) - Or any other containerization tool.
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 runpnpm 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:
- Update
.env
(opens in a new tab):PRI_DEV
: set to"false"
if you don't want to deploy theDevSystem
contract.PRI_CHAIN_ID
: set to the chain you want to deploy to; you will also need to add or update the[profile.<chain_id>]
field inpackages/contracts/foundry.toml
(opens in a new tab).
- 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
- 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:
@primodiumxyz/contracts/src/codegen/tables
(opens in a new tab): Generated Solidity contracts for each table.@primodiumxyz/contracts/mud.config.ts
(opens in a new tab): Configuration file that defines each table compliant with the open MUD standard.
Contract Systems:
@primodiumxyz/contracts/src/codegen/world
(opens in a new tab): Generated Solidity interfaces for each publicly-accessible system.
Contract Prototype Table Data:
@primodiumxyz/contracts/src/codegen/prototypes/AllPrototype.sol
(opens in a new tab): Data populated in prototype tables that store game configuration data such as resource requirements and building costs.
Contract Prototype Generation Scripts:
@primodiumxyz/contracts/src/codegen/scripts/CreateTerrain.sol
(opens in a new tab): Foundry script (opens in a new tab) for populating terrain ore distribution.