yarn add @xchainjs/xchain-litecoin
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}`)
}
}
}
//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}`)
}
}