chaingate
Version:
Multi-chain cryptocurrency SDK for TypeScript — unified API for Bitcoin, Ethereum, Litecoin, Dogecoin, Bitcoin Cash, Polygon, Arbitrum, and any EVM-compatible chain. Create wallets, query balances, send transactions, and manage tokens and NFTs across UTXO
110 lines (109 loc) • 4.04 kB
TypeScript
import { Connector } from '../../Connector';
import type { AddressOptions } from '../../Connector';
import { UtxoExplorer } from '../../../Explorer/UtxoExplorer';
import type { Wallet } from '../../../Wallet/Wallet';
import { Amount } from '../../../utils/Amount';
import type { BchAddressType, BchNetworkDescriptor } from '../../../ChainGate/networks';
import { BchTransaction } from './BchTransaction';
import { CustomUtxoTransaction } from '../CustomUtxoTransaction';
import type { CustomUtxoTransactionParams } from '../CustomUtxoTransaction';
/** Options for resolving a Bitcoin Cash wallet address. */
export interface BchAddressOptions extends AddressOptions {
/** Address type override. When omitted the network's default (`'cashaddr'`) is used. */
addressType?: BchAddressType;
}
/**
* Connector for Bitcoin Cash (BCH).
*
* @example
* ```ts
* const cg = new ChainGate();
* const bch = cg.connect(cg.networks.bitcoincash, wallet);
*
* // Default address (cashaddr)
* const addr = await bch.address();
*
* // Legacy address
* const legacyAddr = await bch.address({ addressType: 'legacy' });
*
* const balance = await bch.addressBalance();
*
* const amount = cg.networks.bitcoincash.amount('0.01');
* const tx = await bch.transfer(amount, 'bitcoincash:qq...');
* ```
*/
export declare class BchConnector extends Connector<Wallet, UtxoExplorer, BchNetworkDescriptor> {
/** @internal */
constructor(wallet: Wallet, explorer: UtxoExplorer, network: BchNetworkDescriptor);
/**
* Resolves the effective address type and derivation path from the given options.
* @internal
*/
private resolveAddressOptions;
/**
* Returns the address for this wallet on the Bitcoin Cash network.
*
* - **HD wallets**: derives at `{derivationPath}/{index}` using the derivation
* path for the selected address type (or the network default).
* - **Single-key wallets**: only index `0` is valid. The address type determines
* the encoding (cashaddr or legacy) of the same public key.
* - **XpubWallet**: derives at `m/0/{index}`.
*/
address(options?: BchAddressOptions): Promise<string>;
/**
* Returns the confirmed and unconfirmed balance for this wallet's address.
*/
addressBalance(options?: BchAddressOptions): Promise<{
address: string;
confirmed: Amount;
unconfirmed: Amount;
}>;
/**
* Returns paginated transaction history for this wallet's address.
*
* @param page - Pagination cursor.
*/
addressHistory(page?: string, options?: BchAddressOptions): Promise<{
page: number;
transactions: Array<{
height: number;
txid: string;
amount: Amount;
addressBalance: Amount;
}>;
}>;
/**
* Returns paginated UTXOs for this wallet's address.
*
* @param page - Pagination cursor.
*/
addressUtxos(page?: string, options?: BchAddressOptions): Promise<{
address: string;
page: number;
utxos: Array<{
txid: string;
n: number;
amount: Amount;
height: number;
script: string;
}>;
}>;
/**
* Creates a BCH transfer transaction with recommended fees.
*
* @param amount - Amount to send.
* @param toAddress - Recipient address (cashaddr or legacy).
*
* @throws {@link UnsupportedOperationError} if the wallet is view-only.
*/
transfer(amount: Amount, toAddress: string, options?: BchAddressOptions): Promise<BchTransaction>;
/**
* Creates a custom BCH transaction with caller-defined inputs and outputs.
*
* Addresses may be provided in CashAddr or legacy format.
*
* @param params - Inputs and outputs for the transaction.
* @throws {@link UnsupportedOperationError} if the wallet is view-only.
*/
createTransaction(params: CustomUtxoTransactionParams, options?: BchAddressOptions): CustomUtxoTransaction;
}