Document not found (404)
+This URL is invalid, sorry. Please use the navigation bar or search to continue.
+ +diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd5106f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_STORE diff --git a/404.html b/404.html new file mode 100644 index 0000000..5db485e --- /dev/null +++ b/404.html @@ -0,0 +1,167 @@ + + +
+ + +This URL is invalid, sorry. Please use the navigation bar or search to continue.
+ +Components are plain data structures (classes or structs) that contain data relevant to a specific aspect of an entity. They don't have any logic or methods. Examples of components could be a "Position" component containing x, y, z coordinates.
+Create a Position component with
+bolt component position
+
+which will add a new component to your workspace:
++ ++#![allow(unused)] +fn main() { +use bolt_lang::*; + +declare_id!("Fn1JzzEdyb55fsyduWS94mYHizGhJZuhvjX6DVvrmGbQ"); + +#[component] +#[derive(Copy)] +pub struct Position { + pub x: i64, + pub y: i64, + pub z: i64, +} +} +
Systems contain the logic that processes and manipulates entities based on their components. A system will typically operate on all entities that have a specific set of components. For example, a "Movement" system might update the position of a "Position" component
+Create a movement system with with
+bolt system system-movement
+
+which will add a new system to your workspace:
++ ++#![allow(unused)] +fn main() { +use bolt_lang::*; +use component_position::Position; + +declare_id!("FSa6qoJXFBR3a7ThQkTAMrC15p6NkchPEjBdd4n6dXxA"); + +#[system] +#[program] +pub mod system_movement { + + pub fn execute(ctx: Context<Components>, args_p: Vec<u8>) -> Result<Components> { + + let position = &mut ctx.accounts.position; + + position.x += 1; + position.y += 1; + + Ok(ctx.accounts) + } + + // Define the input components + #[system_input] + pub struct Components { + pub position: Position, + } +} +} +
This chapter walks you through the installation process and the folder structure of an anchor workspace.
+ +To initialize a new project, simply run:
+bolt init <new-workspace-name>
+
+This creates a new bolt workspace you can move into. The following are some of the important files in the folder:
+.anchor
folder: It includes the most recent program logs and a local ledger that is used for testingapp
folder: An empty folder that you can use to hold your frontend if you use a monorepoprograms
folder: This folder contains your programs. It can contain multiple but initially only contains a program with the same name as <new-workspace-name>
. This program already contains a lib.rs
file with some sample code.tests
folder: The folder that contains your E2E tests. It will already include a file that tests the sample code in the programs/<new-workspace-name>
.migrations
folder: In this folder you can save your deploy and migration scripts for your programs.Anchor.toml
file: This file configures workspace wide settings for your programs. Initially, it configures
+[programs.localnet]
)[registry]
)[provider]
)[scripts]
). The test
script is run when running anchor test
. You can run your own scripts with anchor run <script_name>
.Run the example unit test with the following command:
+bolt test
+
+This command will register a new World instance, create an entity, attach a component, and execute a system on it.
+The test script is available as a reference under the tests
folder.
Bolt is built on top of Anchor and supports all Anchor commands, in addition to some extensions. For the complete list of Anchor commands, refer to the Anchor book.
+ +Go here to install Rust.
+Go here to install Solana and then run solana-keygen new
to create a keypair at the default location. Anchor uses this keypair to run your program tests.
Go here to install Yarn.
+Bolt
using npm or yarn.With npm:
+npm install -g @magicblock-labs/bolt-cli
+
+With yarn:
+yarn global add @magicblock-labs/bolt-cli
+
+Bolt
using Cargo.cargo install --git https://github.com/magicblock-labs/bolt --locked --force
+
+On Linux systems you may need to install additional dependencies if cargo install fails. E.g. on Ubuntu:
+sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y pkg-config build-essential libudev-dev
+
+Verify the installation.
+bolt -h
+
+
+ The World Program is the entrypoint for creating world instances, entities, attaching components, and executing systems within a unified framework.
+Ongoing development efforts are focused on delivering multiple client SDKs and integrations. The World Program, a standard Anchor program, expose its Interface Definition Language (IDL) published on-chain for seamless interaction.
+To install the Bolt SDK, execute the following command:
+npm install @magicblock-labs/bolt-sdk
+
+Create a new world instance as demonstrated below:
+const registry = await Registry.fromAccountAddress(provider.connection, registryPda);
+worldId = new anchor.BN(registry.worlds);
+worldPda = FindWorldPda(new anchor.BN(worldId))
+const initializeWorldIx = createInitializeNewWorldInstruction(
+ {
+ world: worldPda,
+ registry: registryPda,
+ payer: provider.wallet.publicKey,
+ });
+
+const tx = new anchor.web3.Transaction().add(initializeWorldIx);
+const txSign = await provider.sendAndConfirm(tx);
+
+To add a new entity:
+const world = await World.fromAccountAddress(provider.connection, worldPda);
+const entityId = new anchor.BN(world.entities);
+entityPda = FindEntityPda(worldId, entityId);
+
+let createEntityIx = createAddEntityInstruction({
+ world: worldPda,
+ payer: provider.wallet.publicKey,
+ entity: entityPda,
+});
+const tx = new anchor.web3.Transaction().add(createEntityIx);
+await provider.sendAndConfirm(tx);
+
+For attaching components:
+const positionComponentPda = FindComponentPda(positionComponent.programId, entityPda, "");
+let initComponentIx = createInitializeComponentInstruction({
+ payer: provider.wallet.publicKey,
+ entity: entityPda,
+ data: positionComponentPda,
+ componentProgram: positionComponent.programId,
+});
+const tx = new anchor.web3.Transaction().add(initComponentIx);
+await provider.sendAndConfirm(tx);
+
+To apply a system:
+let applySystemIx = createApplyInstruction({
+ componentProgram: positionComponent.programId,
+ boltSystem: systemMovement.programId,
+ boltComponent: positionComponentPda,
+});
+const tx = new anchor.web3.Transaction().add(applySystemIx);
+await provider.sendAndConfirm(tx);
+
+
+ Welcome to The Bolt Book! ⚡
+++Bolt is an open-source project, currently in its early development phase, and warmly welcomes contributors. For additional resources, join the community on Discord.
+
This chapter covers what bolt is, how its documentation is structured, and what you should know to have a good time with this guide.
+If you find errors or something doesn't work, please report it here.
+ +