UNPKG

@arklabs/wallet-sdk

Version:

Bitcoin wallet SDK with Taproot and Ark integration

62 lines (61 loc) 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EsploraProvider = exports.ESPLORA_URL = void 0; exports.ESPLORA_URL = { bitcoin: "https://mempool.space/api", testnet: "https://mempool.space/testnet/api", signet: "https://mempool.space/signet/api", mutinynet: "https://mutinynet.com/api", regtest: "http://localhost:3000", }; class EsploraProvider { constructor(baseUrl) { this.baseUrl = baseUrl; } async getCoins(address) { const response = await fetch(`${this.baseUrl}/address/${address}/utxo`); if (!response.ok) { throw new Error(`Failed to fetch UTXOs: ${response.statusText}`); } return response.json(); } async getFeeRate() { const response = await fetch(`${this.baseUrl}/v1/fees/recommended`); if (!response.ok) { throw new Error(`Failed to fetch fee rate: ${response.statusText}`); } const fees = await response.json(); return fees.halfHourFee; // Return the "medium" priority fee rate } async broadcastTransaction(txHex) { const response = await fetch(`${this.baseUrl}/tx`, { method: "POST", headers: { "Content-Type": "text/plain", }, body: txHex, }); if (!response.ok) { const error = await response.text(); throw new Error(`Failed to broadcast transaction: ${error}`); } return response.text(); // Returns the txid } async getTxOutspends(txid) { const response = await fetch(`${this.baseUrl}/tx/${txid}/outspends`); if (!response.ok) { const error = await response.text(); throw new Error(`Failed to get transaction outspends: ${error}`); } return response.json(); } async getTransactions(address) { const response = await fetch(`${this.baseUrl}/address/${address}/txs`); if (!response.ok) { const error = await response.text(); throw new Error(`Failed to get transactions: ${error}`); } return response.json(); } } exports.EsploraProvider = EsploraProvider;