Socket
Socket
Sign inDemoInstall

@initia/gclient.js

Package Overview
Dependencies
5
Maintainers
4
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @initia/gclient.js

## How to install


Version published
Maintainers
4
Created

Readme

Source

Initia Game SDK for client

How to install

$ npm install @initia/gclient.js

How to use

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);

FAQs

Last updated on 26 May 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc