You can visit the xchain-bitcoincash package repository to get the updated peer dependencies by looking at the "peerDependencies" object in the "package.json" file.
Testing
yarn install
yarn test
Example
Connect Wallet to New Bitcoincash Client
The network default is Mainnet
// Imports
import { Client } from "@xchainjs/xchain-bitcoincash"
// Connect wallet to new BitcoinCash Client & validate address
const connectWallet = async () => {
let phrase = "phrase"
const bchClient = new Client({phrase})
let address = bchClient.getAddress()
let isValid = bchClient.validateAddress(address)
if( isValid === true ){
try {
const balance = await bchClient.getBalance(address)
let assetAmount = (baseToAsset(balance[0].amount)).amount()
console.log(`With balance: ${assetAmount}`)
} catch (error) {
console.log(`Caught: ${error}`)
}
} else {
console.log(`Address ${address} is not valid`)
}
}
Transfer Using BitcoinCash Client
Transaction parameters. The default fee rate is: 1
Returns transaction hash string
//Imports
import { assetToBase, assetAmount, AssetBCH } from "@xchainjs/xchain-util"
// Convert amount to transfer to BaseAmount using helper functions
const transferBitcoinCash = async () => {
let amountToTransfer = 0.01
let recipient = await getRecipientAddress()
let phrase = "phrase"
const bchClient = new Client({ phrase })
let amount = assetToBase(assetAmount(amountToTransfer, BCH_DECIMAL))
console.log("Building transaction")
try {
const txid = await bchClient.transfer({
"asset": AssetBCH,
"amount": amount,
"recipient":recipient,
})
console.log(`Transaction sent: ${txid}`)
} catch (error) {
console.log(`Caught: ${error}`)
}
}
// Build transaction with feeRate adjustment
const feeRates = await bchClient.getFeeRates()
console.log(feeRates.average, feeRates.fast, feeRates.fastest)
try {
const txid = await bchClient.transfer({
"asset": AssetBCH,
"amount": amount,
"recipient":recipient,
feeRate: feeRates.average // default is 1
})
console.log(`Transaction sent: ${txid}`)
} catch (error) {
console.log(`Caught: ${error}`)
}
Get Current Fees & Fee Rates.
getFees() returns fees in base amount i.e BCH Fees Fast: 0.00000234 Fastest: 0.0000117 Average: 0.00000117
getFeeRates() returns feeRates as number