What You’ll Learn
- How to create Bolt components with the
#[component(delegate)]attribute - How to build systems that operate on components
- How to initialize a Bolt world and add entities
- How to delegate component accounts to Ephemeral Rollups
- How to apply systems for low-latency execution
- How to undelegate components back to Solana
Program Structure
The Bolt counter example consists of two main parts:Component
- Counter - A delegatable component that stores a
countvalue
System
- Increase - A system that increments the counter component by 1
Software Requirements
Bolt has its own build tool. Ensure you have it installed before building.
Build and Test
1
Build the program
Build using the Bolt CLI:
2
Configure Ephemeral Rollup endpoints
Set the environment variables for the Ephemeral Rollup:
3
Run tests
Execute the test suite (skip deploy if already deployed):
Component Implementation
The Counter component uses the#[component(delegate)] attribute to make it delegatable:
The
#[component(delegate)] attribute automatically generates the necessary code to make this component delegatable to Ephemeral Rollups.System Implementation
The Increase system operates on the Counter component:Systems in Bolt are pure functions that take components as input and return the modified components.
TypeScript Client Usage
Initialize World and Entity
Delegate Component to Ephemeral Rollups
Apply System on Ephemeral Rollups
Systems are applied to entities, and Bolt automatically loads the required components for execution.
Undelegate Component
Running with Local Ephemeral Rollup
1
Install the local validator
2
Start the local validator
Run the validator pointing to devnet as the reference:
3
Run tests with local validator
Point the tests to the local validator:
Key Features
ECS Architecture
Entity-Component-System pattern for composable game logic
Delegatable Components
Components can be delegated to Ephemeral Rollups with a single attribute
Composable Systems
Systems operate on components and can be combined for complex behaviors
Built for Games
Designed specifically for onchain game development patterns
ECS Concepts
Entities
Entities are unique identifiers (PDAs) that group components together. They represent game objects or actors.Components
Components are data containers attached to entities. In this example,Counter is a component that stores a count value.
Systems
Systems contain the logic that operates on components. TheIncrease system increments the counter.