# Initia game.js

`@initia/game.js` is a library that provides various features for gaming such as Dex, NFT, Account Abstraction, and Fee Grant.

The `@initia/game.js` is comprised of two main parts: [`@initia/gclient.js`](./client) and [`@initia/gserver.js`](./server).

The `@initia/gclient.js` is responsible for handling the client-side aspects of the game, such as user login and interaction with the player. This section of the library is executed on the user's device.

On the other hand, the `@initia/gserver.js` handles the server-side aspects of the game, including game logic. This section of the library is executed on the game's server.

## How to install

```bash
$ npm install @initia@game.js
```

## How to use

```ts
import { LCDClient, MnemonicKey, Wallet } from '@initia/initia.js';
import { gclient, gserver } from '@initia/game.js';

const lcdUrl = 'https://stone-rest.initia.tech';
const mnemonic = 'YOUR_MNEMONIC';

async function main() {
  // client - refer to https://github.com/initia-labs/game.js/blob/main/client/README.md for details
  const clientWallet = new gclient.Wallet(lcdUrl);
  await clientWallet.connectMnemonic(mnemonic);

  // server - refer to https://github.com/initia-labs/game.js/blob/main/server/README.md for details
  const key = new MnemonicKey({ mnemonic });
  const lcd = new LCDClient(lcdUrl, {
    chainId: 'stone-8',
    gasPrices: '0.15uinit',
    gasAdjustment: '2.0',
  });
  const serverWallet = new Wallet(lcd, key);
  const broadcastManager = new gserver.BroadcastManager(serverWallet, broadcastCallBack);
  await broadcastManager.init();
}

function broadcastCallBack(
  isSuccess: boolean,
  txHash: string,
  reason?: string
) {
  if (isSuccess) {
    console.log(`Tx(${txHash}) broadcast success`);
  } else {
    console.log(`Tx(${txHash}) broadcast failed due to ${reason}`);
  }
}

main().catch(console.error);
```
