@iota-big3/sdk-blockchain
Version:
Comprehensive blockchain integration platform with multi-chain support, smart contracts, DeFi protocols, NFT infrastructure, Bitcoin support, and seamless SDK ecosystem integration for IOTA Big3
110 lines • 3.59 kB
JavaScript
/**
* Bitcoin RPC Client
* Handles communication with Bitcoin Core nodes
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.BitcoinRPCClient = void 0;
const tslib_1 = require("tslib");
const axios_1 = tslib_1.__importDefault(require("axios"));
class BitcoinRPCClient {
constructor(config) {
this.id = 1;
this.client = axios_1.default.create({
baseURL: config.url,
timeout: config.timeout || 30000,
auth: {
username: config.username,
password: config.password
},
headers: {
'Content-Type': 'application/json'
}
});
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async call(method, params = []) {
try {
const response = await this.client.post('', {
jsonrpc: '2.0',
id: this.id++,
method,
params
});
if (response.data.error) {
throw new Error(`RPC Error: ${response.data.error.message}`);
}
return response.data.result;
}
catch (error) {
if (axios_1.default.isAxiosError(error)) {
throw new Error(`Network Error: ${error.message}`);
}
throw error;
}
}
// Blockchain info
async getBlockchainInfo() {
return this.call('getblockchaininfo');
}
async getBlockCount() {
return this.call('getblockcount');
}
async getBlock(blockhash, verbosity = 1) {
return this.call('getblock', [blockhash, verbosity]);
}
async getBlockHash(height) {
return this.call('getblockhash', [height]);
}
// Address operations
async validateAddress(address) {
return this.call('validateaddress', [address]);
}
async getNewAddress(label = '', addressType = 'bech32') {
return this.call('getnewaddress', [label, addressType]);
}
// UTXO operations
async listUnspent(minconf = 1, maxconf = 9999999, addresses = []) {
return this.call('listunspent', [minconf, maxconf, addresses]);
}
// Transaction operations
async createRawTransaction(inputs, outputs) {
return this.call('createrawtransaction', [inputs, outputs]);
}
async signRawTransactionWithWallet(hexstring) {
return this.call('signrawtransactionwithwallet', [hexstring]);
}
async sendRawTransaction(hexstring) {
return this.call('sendrawtransaction', [hexstring]);
}
async getTransaction(txid, includeWatchonly = false) {
return this.call('gettransaction', [txid, includeWatchonly]);
}
// Fee estimation
async estimateSmartFee(confTarget, estimateMode = 'CONSERVATIVE') {
return this.call('estimatesmartfee', [confTarget, estimateMode]);
}
// Wallet operations
async getBalance(minconf = 1) {
return this.call('getbalance', ['*', minconf]);
}
async listTransactions(label = '*', count = 10, skip = 0) {
return this.call('listtransactions', [label, count, skip]);
}
// Network info
async getNetworkInfo() {
return this.call('getnetworkinfo');
}
async getPeerInfo() {
return this.call('getpeerinfo');
}
// Testing connection
async ping() {
await this.call('ping');
}
async uptime() {
return this.call('uptime');
}
}
exports.BitcoinRPCClient = BitcoinRPCClient;
//# sourceMappingURL=bitcoin-rpc-client.js.map
;