How to Use
Installation
yarn add @xchainjs/xchain-cosmosPeer Dependencies
You can visit the xchain-cosmos package repository to get the updated peer dependencies by looking at the "peerDependencies" object in the "package.json" file.
Extras
Important note: Make sure to install same version of cosmos-client/core as xchain-cosmos is using (currently "@cosmos-client/core": "^0.45.1", ). In other case things might break.
Testing
yarn install
yarn testExamples
Connect Wallet to New Cosmos Client
Create a new thorchain client
Set phrase and network when creating an instance.
The network default is Mainnet
//Imports
import { AssetAtom, Client, COSMOS_DECIMAL } from "@xchainjs/xchain-cosmos"
import { assetToBase, baseToAsset, assetAmount } from "@xchainjs/xchain-util"
// Create new instance of the client and query chain for balances.
const connectWallet = async () => {
let phrase = "phrase"
const cosmosClient = new Client({phrase})
let address = cosmosClient.getAddress()
let isValid = cosmosClient.validateAddress(address)
console.log(address)
if(isValid === true){
try {
const balance = await cosmosClient.getBalance(address)
let assetAmount = (baseToAsset(balance[0].amount)).amount()
console.log(`Adress: ${address} with balance ${assetAmount}`)
} catch (error) {
console.log(`Caught: ${error} `)
}
} else {
console.log(`Address: ${address} is invalid`)
}
}
Transfer ATOM using Cosmos Client
Create a new Cosmos client instance Convert amount to transfer to base amount Build transaction.
Get Transaction Data & Transaction History
Retrieve transaction data using transaction hash and address
Get Transfer Fees
Get Network and Explorer Data
Last updated