Skip to content

Commit

Permalink
📝 Simplify bolt ts syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielePicco committed Apr 6, 2024
1 parent b131984 commit e6b5a6b
Showing 1 changed file with 17 additions and 29 deletions.
46 changes: 17 additions & 29 deletions _posts/2024-03-01-bolt-v0.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,59 +117,47 @@ npm install @magicblock-labs/bolt-sdk --save-dev
##### Create a world instance

```ts
const world = await World.fromAccountAddress(provider.connection, worldPda);
const entityId = new anchor.BN(world.entities);
entityPda = FindEntityPda(worldId, entityId);

let createEntityIx = createAddEntityInstruction({
world: worldPda,
const initNewWorld = await InitializeNewWorld({
payer: provider.wallet.publicKey,
entity: entityPda,
connection: provider.connection,
});
const tx = new anchor.web3.Transaction().add(createEntityIx);
await provider.sendAndConfirm(tx);
await provider.sendAndConfirm(initNewWorld.transaction);
```

###### Add a new entity

```ts
const world = await World.fromAccountAddress(provider.connection, worldPda);
const entityId = new anchor.BN(world.entities);
entityPda = FindEntityPda(worldId, entityId);

let createEntityIx = createAddEntityInstruction({
world: worldPda,
const addEntity = await AddEntity({
payer: provider.wallet.publicKey,
entity: entityPda,
world: initNewWorld.worldPda,
connection: provider.connection,
});
const tx = new anchor.web3.Transaction().add(createEntityIx);
await provider.sendAndConfirm(tx);
await provider.sendAndConfirm(addEntity.transaction);
```

##### Attach the Position component to the the entity

```ts
const positionComponentPda = FindComponentPda(positionComponent.programId, entityPda, "");
let initComponentIx = createInitializeComponentInstruction({
const initComponent = await InitializeComponent({
payer: provider.wallet.publicKey,
entity: entityPda,
data: positionComponentPda,
componentProgram: positionComponent.programId,
entity: addEntity.entityPda,
componentId: positionComponent.programId,
});
const tx = new anchor.web3.Transaction().add(initComponentIx);
await provider.sendAndConfirm(tx);
await provider.sendAndConfirm(initComponent.transaction);
```

##### Execute the movement system on the position Component

```ts
let applySystemIx = createApplyInstruction({
componentProgram: positionComponent.programId,
boltSystem: systemMovement.programId,
boltComponent: positionComponentPda,
const applySystem = await ApplySystem({
authority: provider.wallet.publicKey,
system: systemMovement.programId,
entity: addEntity.entityPda,
components: [positionComponent.programId],
});
const tx = new anchor.web3.Transaction().add(applySystemIx);
await provider.sendAndConfirm(tx);
await provider.sendAndConfirm(applySystem.transaction);
```

In this simple example we have created an entity Player that holds a Position component with x,y,z coordinates. We can execute the movement system to change its state.
Expand Down

0 comments on commit e6b5a6b

Please sign in to comment.