– Read Me is default dust template text –
This repository contains example programs for DUST that demonstrate different patterns and use cases for smart entities in the game.
Programs in DUST are smart contracts that react to world events through hooks. They can be attached to entities like chests, force fields, spawn tiles, and beds to add custom behavior.
File: packages/contracts/src/BaseProgram.sol
The foundation contract that all programs inherit from. It provides:
File: packages/contracts/src/ChestProgram.sol
A minimal chest program template that shows the basic structure for handling transfers.
Key Features:
ITransfer
interfaceFile: packages/contracts/src/ChestCounterProgram.sol
A chest that only allows transfers when a global counter is odd.
Key Features:
Counter
tableHow it works:
CounterSystem
File: packages/contracts/src/systems/CounterSystem.sol
A simple system that manages a global counter, used by ChestCounterProgram.
Key Features:
increment()
- Increases counter by 1decrement()
- Decreases counter by 1setValue(uint256)
- Sets counter to specific valuegetValue()
- Returns current counter valueNote: This is a System, not a Program. It provides callable functions rather than reacting to hooks.
File: packages/contracts/src/ForceFieldProgram.sol
Template for force field programs that can react to various events within their area.
Available Hooks:
onMine
- When blocks are minedonBuild
- When blocks are builtonHit
- When the force field is hitonEnergize
- When energy is addedFile: packages/contracts/src/SpawnTileProgram.sol
Template for spawn tile programs that react to player spawning.
Available Hooks:
onSpawn
- When a player spawns on the tileFile: packages/contracts/src/BedProgram.sol
Template for bed programs that react to sleep events.
Available Hooks:
onSleep
- When a player sleepsonWakeup
- When a player wakes upUnderstanding when to use Programs vs Systems is crucial:
Programs:
IHookInterface
, System
, and BaseProgram
Systems:
System
When programs need configuration that happens outside of hook events, use a separate System:
// Program handles reactive logic
contract MyProgram is ITransfer, System, BaseProgram {
function onTransfer(...) external onlyWorld {
// Check rules, enforce constraints
}
}
// System handles configuration
contract MySystem is System {
function configure(...) external {
// Set parameters, update tables
}
}
pnpm install
cd packages/contracts
pnpm build
cd packages/contracts
pnpm test
Tests are provided in packages/contracts/test/
:
ChestCounterProgram.t.sol
- Comprehensive tests showing program interactionKey testing patterns:
counterSystem
from CounterSystemLib.sol
)packages/contracts/mud.config.ts
to something uniquepnpm build
pnpm deploy:local
pnpm deploy:redstone
After deployment:
packages/contracts/.mud/local/systems.json
pnpm attach <entity_id> <program_id>
Programs MUST explicitly inherit from System
even if BaseProgram
already does. MUD’s build system only detects direct inheritance.
TransferData
is automatically available when importing ITransfer
All table operations go through generated libraries in packages/contracts/src/codegen/tables/
dust-template/
├── packages/
│ ├── contracts/ # Smart contracts
│ │ ├── src/
│ │ │ ├── systems/ # Systems (callable functions)
│ │ │ ├── codegen/ # Generated code (do not edit)
│ │ │ └── *.sol # Programs and base contracts
│ │ ├── test/ # Tests
│ │ └── mud.config.ts # MUD configuration
│ └── client/ # Frontend application
└── CLAUDE.md # Comprehensive development guide