Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Latest commit

 

History

History
56 lines (39 loc) · 1.64 KB

README.md

File metadata and controls

56 lines (39 loc) · 1.64 KB

@shapeshiftoss/unchained-client

Provides a TypeScript axios client to interact with all supported unchained APIs.

Installing

Using npm:

npm install @shapeshiftoss/unchained-client

Using yarn:

yarn add @shapeshiftoss/unchained-client

Resources

  • CAIP-2 naming conventions used for chainId
  • CAIP-19 naming conventions used for assetId

Usage

import * as unchained from '@shapeshiftoss/unchained-client'

const address = 'cosmos1t5u0jfg3ljsjrh2m9e47d4ny2hea7eehxrzdgd'

// configuration for the api client
const config = new unchained.cosmos.Configuration({ basePath: 'https://dev-api.cosmos.shapeshift.com' })

// create new instance of the api client
const apiClient = new unchained.cosmos.V1Api(config)

// create new instance of the ws client
const wsClient = new unchained.ws.Client<unchained.cosmos.Tx>('wss://dev-api.cosmos.shapeshift.com')

// create new instance of the transaction parser
// chainId is in the format of [Caip2](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md)
const parser = new unchained.cosmos.TransactionParser({ chainId: 'cosmos:cosmoshub-4' })

// example api client request
const { data } = await apiClient.getBalance({ pubkey: address })

// example websocket subscription for new transaction and transaction parsing
await this.providers.ws.subscribeTxs(
  'test',
  { topic: 'txs', addresses: [address] },
  async (msg) => {
        const tx = await parser.parse(msg.data, msg.address)
  },
  (err) => console.warn(err)
)