How to Use

Installation

yarn add @xchainjs/xchain-doge

Peer Dependencies

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

Testing

yarn install
yarn test

Examples

Connect Wallet to New Doge Client and Check Balance

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

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

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

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

Last updated