Skip to content

Commit

Permalink
feat: Update documentation for bolt world program to use the higher l…
Browse files Browse the repository at this point in the history
…evel API (#5)

# Summary

The documentation is still using the first version of the API generated
by solita directly.
We update it to use a more high-level api provided by typescript
bolt-sdk.

# Details

- use `InitializeNewWorld` instead of
`createInitializeNewWorldInstruction`
- use `AddEntity` instead of `createAddEntityInstruction`
- use `InitializeComponent` instead of
`createInitializeComponentInstruction`
- use `ApplySystem` instead of `createApplySystemInstruction`

# Notes

N/A
  • Loading branch information
crypto-vincent authored Jun 13, 2024
1 parent cdfe6f5 commit a368391
Showing 1 changed file with 20 additions and 37 deletions.
57 changes: 20 additions & 37 deletions BOLT/getting_started/world_program.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,70 +26,53 @@ Initiating a project with bolt init automatically generates a simple usage examp
Create a new world instance as demonstrated below:

```typescript
const registry = await Registry.fromAccountAddress(
provider.connection,
registryPda
);
const worldId = new anchor.BN(registry.worlds);
const worldPda = FindWorldPda(new anchor.BN(worldId));
const initializeWorldIx = createInitializeNewWorldInstruction({
world: worldPda,
registry: registryPda,
const initializeNewWorld = await InitializeNewWorld({
payer: provider.wallet.publicKey,
connection: provider.connection,
});

const tx = new anchor.web3.Transaction().add(initializeWorldIx);
const txSign = await provider.sendAndConfirm(tx);
const signature = await provider.sendAndConfirm(initializeNewWorld.transaction);
const worldPda = initializeNewWorld.worldPda; // we can use this later
```

## Adding a New Entity

To add a new entity:

```typescript
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: worldPda,
connection: provider.connection,
});
const tx = new anchor.web3.Transaction().add(createEntityIx);
await provider.sendAndConfirm(tx);
const signature = await provider.sendAndConfirm(addEntity.transaction);
const entityPda = addEntity.entityPda; // we can use this later
```

## Attaching Components to an Entity

For attaching components:

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

## Applying Systems

To apply a system:

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

0 comments on commit a368391

Please sign in to comment.