> For the complete documentation index, see [llms.txt](https://xchainjs.gitbook.io/xchainjs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xchainjs.gitbook.io/xchainjs/clients/xchain-utxo/xchain-litecoin/how-to-use.md).

# How to Use

## Installation <a href="#installation" id="installation"></a>

```
yarn add @xchainjs/xchain-litecoin
```

### Peer Dependencies

You can visit the [xchain-litecoin](https://github.com/xchainjs/xchainjs-lib/blob/7c7776da37315f636d7a8dc6adde2d327f47c277/packages/xchain-litecoin/package.json#L49) 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 <a href="#basic-usage-examples" id="basic-usage-examples"></a>

#### Connect Wallet to New Litecoin Client <a href="#connect-wallet-to-new-litecoin-client" id="connect-wallet-to-new-litecoin-client"></a>

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 <a href="#transfer-litecoin-using-litecoin-client-instance" id="transfer-litecoin-using-litecoin-client-instance"></a>

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}`)
    }
}
```
