メインコンテンツへスキップ
World Program は、統一フレームワーク内で world instance の作成、entities の生成、components のアタッチ、systems の実行を行うためのエントリーポイントです。

クライアント開発

現在は、複数のクライアント SDK と統合の提供に向けた開発が進められています。 World Program は標準的な Anchor program であり、シームレスな連携のために Interface Definition Language(IDL)をオンチェーンで公開しています。

TypeScript SDK のインストール

Bolt SDK をインストールするには、次のコマンドを実行します。
npm install @magicblock-labs/bolt-sdk
bolt init でプロジェクトを開始すると、bolt-sdk の簡単な使用例が自動生成されます。

新しい World Instance を作成する

以下のように新しい world instance を作成します。
const initializeNewWorld = await InitializeNewWorld({
  payer: provider.wallet.publicKey,
  connection: provider.connection,
});
const signature = await provider.sendAndConfirm(initializeNewWorld.transaction);
const worldPda = initializeNewWorld.worldPda; // 後で利用できます

新しい Entity を追加する

新しい entity を追加するには:
const addEntity = await AddEntity({
  payer: provider.wallet.publicKey,
  world: worldPda,
  connection: provider.connection,
});
const signature = await provider.sendAndConfirm(addEntity.transaction);
const entityPda = addEntity.entityPda; // 後で利用できます

Entity に Components をアタッチする

components をアタッチするには:
const initializeComponent = await InitializeComponent({
  payer: provider.wallet.publicKey,
  entity: entityPda,
  componentId: positionComponent.programId,
});
const signature = await provider.sendAndConfirm(
  initializeComponent.transaction
);
const componentPda = initializeComponent.componentPda; // 状態取得に利用できます

Systems を適用する

system を適用するには:
const applySystem = await ApplySystem({
  authority: provider.wallet.publicKey,
  systemId: systemMovement.programId,
  entities: [
    {
      entity: entityPda,
      components: [{ componentId: positionComponent.programId }],
    },
  ],
});
const signature = await provider.sendAndConfirm(applySystem.transaction);