How to Use

Installation

yarn add @xchainjs/xchain-litecoin

Peer Dependencies

You can visit the xchain-litecoin package repository to get the updated peer dependencies by looking at the "devDependencies" object in the "package.json" file.

Testing

yarn install
yarn test

Examples

Connect Wallet to New Litecoin Client

Create a new instance of Litecoin Client Retrieve and validate an address Check the balance of assets at the address The network default is Mainnet


//Imports 
import { Client } from "@xchainjs/xchain-litecoin"

// Connect wallet and retrieve address and balance of assets on address
const connectWallet =async () => {
    let phrase = "phrase"
    const ltcClient = new Client({network: Network.Mainnet, phrase})
    let address = ltcClient.getAddress()
    console.log(address)
    let isValid = ltcClient.validateAddress(address)
    if( isValid === true ){
        try {
            const balance = await ltcClient.getBalance(address)
            let assetAmount = (baseToAsset(balance[0].amount)).amount()
            console.log(`With balance: ${assetAmount}`)
    
        } catch (error) {
            console.log(`Caught: ${error}`)
        }
    }
}

Transfer Litecoin Using Litecoin Client Instance

The default fee rate is 1

//Imports
import { Client, LTC_DECIMAL } from "@xchainjs/xchain-litecoin"
import { assetToBase, baseToAsset, assetAmount } from "@xchainjs/xchain-util"

// Create new ltc Client and call transfer function
// Check what txParams are needed
const transferlitecoin = async () => {
    let amountToTransfer = 0.01
    let recipient = "insert recipient"
    let phrase = "phrase"
    const ltcClient = new Client({ phrase})
    let amount = assetToBase(assetAmount(amountToTransfer, LTC_DECIMAL))
    console.log("Building transaction")
    try {
        const txid = await ltcClient.transfer({
            "amount": amount,
            "recipient": recipient,
            "memo": "memo"         
        })
        console.log(`Transaction sent: ${txid}`)
        const transactionUrl = await ltcClient.getExplorerTxUrl(txid) // returns url for tx
        console.log(`Transaction url: ${transactionUrl}`)
    } catch (error) {
        console.log(`Caught: ${error}`)
    }
}

Last updated