> 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-doge/how-to-use.md).

# How to Use

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

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

### Peer Dependencies

You can visit the [xchain-doge](https://github.com/xchainjs/xchainjs-lib/blob/7c7776da37315f636d7a8dc6adde2d327f47c277/packages/xchain-doge/package.json#L49) package repository to get the updated peer dependencies by looking at the "peerDependencies" object in the "package.json" file.

### Testing <a href="#doge-client-testing" id="doge-client-testing"></a>

```
yarn install
yarn test
```

## Examples <a href="#basic-usage-examples" id="basic-usage-examples"></a>

#### Connect Wallet to New Doge Client and Check Balance <a href="#connect-wallet-to-new-doge-client-and-check-balance" id="connect-wallet-to-new-doge-client-and-check-balance"></a>

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

```
//Imports 
import { Client, DOGE_DECIMAL} from "@xchainjs/xchain-doge"

// Connect wallet to new Client 
const connectWallet = async () => {
    let phrase = "phrase"
    let dogeClient = new Client({ network: Network.Mainnet, phrase})
    let address = dogeClient.getAddress()
    let isValid = dogeClient.validateAddress(address)
    if(isValid === true){
        try {
            const balance = await dogeClient.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 not valid`)
    }
}

```

#### Transfer Dogecoin using dogeClient Instance <a href="#transfer-dogecoin-using-dogeclient-instance" id="transfer-dogecoin-using-dogeclient-instance"></a>

Create a new client instance\
Convert amount to transfer to base\
Build transaction with correct Tx Parameters\
The default fee is set to 1

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

// Call Transfer with TxParams
const transferDoge = async () => {
    let amountToTransfer = 0.01
    let recipient = await getRecipientAddress()
    let phrase = "phrase"
    let dogeClient = new Client({phrase})
    let amount = assetToBase(assetAmount(amountToTransfer, DOGE_DECIMAL))
    console.log("Building transaction", JSON.stringify(amount.amount()))
    try {
        const txid = await dogeClient.transfer({
            "amount": amount,
            "recipient": recipient,
            "memo": "test"
        })
        console.log(`Transaction sent: ${txid}`)

    } catch (error) {
         console.log(`Caught: ${error}`)
    }
}
// Transfer with fee rate set 
    let feeRate = await dogeClient.getFeeRates()
    try {
        const txid = await dogeClient.transfer({
            "amount": amount,
            "recipient": recipient,
            "memo": "test",
            feeRate: feeRate.fastest
        })
        console.log(`Transaction sent: ${txid}`)

    } catch (error) {
         console.log(`Caught: ${error}`)
    }
```

#### Get Transfer Fees and FeeRate Estimations <a href="#get-transfer-fees-and-feerate-estimations" id="get-transfer-fees-and-feerate-estimations"></a>

Create new dogeClient and query getFees & getFeeRates functions\
Fees are returned as base Amounts.

```
// Get fees 
const feeData = async () => {
    let phrase = "phrase"
    let dogeClient = new Client({phrase})
    try {
        const {fast, fastest, average} = await dogeClient.getFees()
        console.log(`Fees Fast: ${baseToAsset(fast).amount()} Fastest: ${baseToAsset(fastest).amount()} Average: ${baseToAsset(average).amount()}`)

    } catch (error) {
         console.log(`Caught: ${error}`)
    }   
}
// Get Fee Rates
const feeRates = async () => {
    let phrase = "phrase"
    let dogeClient = new Client({phrase})
    try {
        const feeRates = await dogeClient.getFeeRates() // returned as number
        console.log(feeRates.average, feeRates.fast, feeRates.fastest)
    } catch (error) {
         console.log(`Caught: ${error}`)
    }   
}

// Get both Fees and Rates
const getFeesWithRates = async () => {
    let phrase = "phrase"
    let dogeClient = new Client({phrase})
    try {
        const feesWithRates = await dogeClient.getFeesWithRates()
        console.log(feesWithRates.fees, feesWithRates.rates)
    } catch (error) {
         console.log(`Caught: ${error}`)
    }  
}

```

#### Get Transaction Data & History <a href="#get-transaction-data--history" id="get-transaction-data--history"></a>

Create a new client instance and query chain data with a hash\
getTransactions() can be filtered with `limit? offset? startTime?`

```

// Retrieve transaction data for a transaction hash 

const transactionData = async () => {
    let phrase = "phrase"
    let dogeClient = new Client({ phrase})
    let hash = "insert hash"
    try {
        const txData = await dogeClient.getTransactionData(hash)
        console.log(`From ${JSON.stringify(txData)}`)   
    } catch (error) {
        console.log(`Caught: ${error}`)
    }
}

// Retrieve transaction history for a particular address

const transactionHistory = async () => {
    let phrase = "phrase"
    let dogeClient = new Client({phrase})
    let Address = dogeClient.getAddress()
    try {
        const txHistory = await dogeClient.getTransactions({address: Address}) 
        console.log(`Found ${txHistory.total.toString()}`)
        txHistory.txs.forEach(tx => console.log(tx.hash))
    } catch (error) {
         console.log(`Caught: ${error}`)
    }    
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xchainjs.gitbook.io/xchainjs/clients/xchain-utxo/xchain-doge/how-to-use.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
