open-index/open-npm huggingface dataset:
npm package: @initia/game.js
Description: The JavaScript Game SDK for Initia
Latest version: 0.0.2

# 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);
```
npm package: @initia/gclient.js
Description: ## How to install
Latest version: 0.0.2

# Initia Game SDK for client

## How to install

```bash
$ npm install @initia/gclient.js
```

## How to use

```ts
import { Wallet, LoginProvider } from '@initia/gclient.js';

async function main() {
  // Create new wallet
  const lcdUrl = 'https://stone-rest.initia.tech';
  const wallet = new Wallet(lcdUrl);
  
  // Connect via social OR via mnemonic
  // connectSocial
  const clientId = 'YOUR_WEB3AUTH_CLIENT_ID';
  await wallet.connectSocial(LoginProvider.GOOGLE, clientId);
  // connectMnemonic
  const mnemonic = 'YOUR_MNEMONIC';
  await wallet.connectMnemonic(mnemonic);

  // Request uinit from faucet
  const faucetUrl = 'https://stone-faucet.initia.tech/claim';
  await wallet.faucet.request(faucetUrl, 'uinit');

  // Send 1 uinit to address
  await wallet.coin.send(
    'init190mzczlkl7rgy7kwkp5pkaas04q4r0rkec5uvf',
    '0x1::native_uinit::Coin',
    1000000
  );

  // Simulate swap of 1 uinit to uusdc
  const { returnAmount, priceImpact } = await wallet.dex.swapSimulate(
    '0x1::native_uinit::Coin',
    '0x1::native_uusdc::Coin',
    '0xfa5f07319724580ef16dcef6ce4d3b0bd0348e48::coins::LP<0x1::native_uusdc::Coin, 0x1::native_uinit::Coin>',
    1000000
  );
  console.log(`uusdc return amount: ${returnAmount}`);
  console.log(`price impact: ${priceImpact}`);

  // Swap 1 uinit to uusdc
  await wallet.dex.swap(
    '0x1::native_uinit::Coin',
    '0x1::native_uusdc::Coin',
    '0xfa5f07319724580ef16dcef6ce4d3b0bd0348e48::coins::LP<0x1::native_uusdc::Coin, 0x1::native_uinit::Coin>',
    1000000
  );

  // Provide liquidity of 1 uinit and equivalent uusdc
  await wallet.dex.provide(
    '0x1::native_uusdc::Coin',
    '0x1::native_uinit::Coin',
    '0xfa5f07319724580ef16dcef6ce4d3b0bd0348e48::coins::LP<0x1::native_uusdc::Coin, 0x1::native_uinit::Coin>',
    10000000,
    1000000
  );

  // Withdraw liquidity
  await wallet.dex.withdraw(
    '0x1::native_uusdc::Coin',
    '0x1::native_uinit::Coin',
    '0xfa5f07319724580ef16dcef6ce4d3b0bd0348e48::coins::LP<0x1::native_uusdc::Coin, 0x1::native_uinit::Coin>',
    1000000
  );

  // Register nft
  await wallet.nft.register('0x589b1e861579c3f07092859db5f8963e1dac50f1::metadata::Metadata');

  // Transfer nft
  await wallet.nft.transfer(
    'init190mzczlkl7rgy7kwkp5pkaas04q4r0rkec5uvf',
    'jhdd:1684743919',
    '0x589b1e861579c3f07092859db5f8963e1dac50f1::metadata::Metadata'
  );

  // Authorize
  await wallet.authz.authorize(
    'init190mzczlkl7rgy7kwkp5pkaas04q4r0rkec5uvf',
    '0x1',
    'nft',
    ['*']
  );
}

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