Skip to main content
A simple counter program demonstrating how to use the Bolt ECS (Entity Component System) framework with Ephemeral Rollups. This example shows how to create delegatable components, apply systems, and manage entities in a game-like architecture.

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 count value

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.
Read more about the Bolt framework: Bolt Documentation

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
Bolt is optimized for ECS patterns. For simpler use cases, consider using Anchor or native Rust instead.

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. The Increase system increments the counter.

World

A world is the top-level container that manages entities and their components.

Source Code

View the complete source code on GitHub: bolt-counter on GitHub