# `@xchainjs/xchain-litecoin`
Source: Dev.to
What this package provides
- A Litecoin Client implementation (UTXO‑style chain)
- Address generation & validation
- Balance, transaction history, and transaction‑data lookup
- Fee‑estimation helpers (
getFeeRates,getFeesWithMemo, etc.)
Source package:
XChainJS docs:
Features
- ✅ TypeScript‑first Litecoin SDK
- ✅ BIP44/84 address derivation support (mainnet & testnet)
- ✅ Create addresses from a mnemonic phrase
- ✅ Validate addresses
- ✅ Get balances, transaction history, and transaction data by hash
- ✅ Transfer LTC
- ✅ Fee‑estimation helpers (
getFeeRates,getFeesWithMemo, …)
How it works (under the hood)
- Uses bitcoinjs-lib for UTXO transaction building and signing.
- Uses SoChain API v2 as the default public data‑provider endpoint.
- Explorer URLs reference Blockstream.
- Depends on shared XChainJS packages:
@xchainjs/xchain-client,@xchainjs/xchain-crypto,@xchainjs/xchain-util.
References
- Docs “How it works”:
- Docs “How to use”:
Installation
Install the package
yarn add @xchainjs/xchain-litecoin
Peer dependencies
According to the official docs, install these as well:
yarn add @xchainjs/xchain-client @xchainjs/xchain-crypto @xchainjs/xchain-util \
axios bitcoinjs-lib coininfo wif
Basic usage examples
Connect wallet to a new Litecoin client
import { Client } from '@xchainjs/xchain-litecoin'
import { Network } from '@xchainjs/xchain-client'
import { baseToAsset } from '@xchainjs/xchain-util'
const connectWallet = async () => {
const phrase = 'your mnemonic phrase here'
const ltcClient = new Client({ network: Network.Mainnet, phrase })
const address = ltcClient.getAddress()
console.log('Address:', address)
const isValid = ltcClient.validateAddress(address)
if (!isValid) throw new Error('Invalid address')
const balances = await ltcClient.getBalance(address)
const readable = baseToAsset(balances[0].amount).amount()
console.log('Balance:', readable.toString())
}
connectWallet().catch(console.error)
Transfer Litecoin (LTC)
import { Client, LTC_DECIMAL } from '@xchainjs/xchain-litecoin'
import { assetToBase, assetAmount } from '@xchainjs/xchain-util'
const transferLitecoin = async () => {
const phrase = 'your mnemonic phrase here'
const recipient = 'ltc recipient address here'
const ltcClient = new Client({ phrase })
const amount = assetToBase(assetAmount(0.01, LTC_DECIMAL))
const txid = await ltcClient.transfer({
amount,
recipient,
memo: 'memo',
})
console.log('TX sent:', txid)
console.log('Explorer:', ltcClient.getExplorerTxUrl(txid))
}
transferLitecoin().catch(console.error)
Get transfer fees and fee‑rate estimations
import { Client } from '@xchainjs/xchain-litecoin'
import { baseToAsset } from '@xchainjs/xchain-util'
const returnFees = async () => {
const phrase = 'your mnemonic phrase here'
const ltcClient = new Client({ phrase })
const { fast, fastest, average } = await ltcClient.getFees()
console.log('Fast:', baseToAsset(fast).amount().toString())
console.log('Fastest:', baseToAsset(fastest).amount().toString())
console.log('Average:', baseToAsset(average).amount().toString())
const feeRates = await ltcClient.getFeeRates()
console.log('FeeRates:', feeRates)
}
returnFees().catch(console.error)
You can pass a feeRate into the transfer parameters:
// feeRates.fastest is a number
await ltcClient.transfer({
amount,
recipient,
memo: 'memo test',
feeRate: feeRates.fastest,
})
Get transaction data & transaction history
import { Client } from '@xchainjs/xchain-litecoin'
const transactionData = async () => {
const phrase = 'your mnemonic phrase here'
const ltcClient = new Client({ phrase })
const hash = 'your tx hash'
const txData = await ltcClient.getTransactionData(hash)
console.log('TxData:', txData)
}
transactionData().catch(console.error)
Useful links
- Package source (GitHub):
- Docs (overview):
- Docs (how it works):
- Docs (how to use):
in-litecoin/how-to-use.html