bitcoincore-node
Version:
A comprehensive Node.js package for interacting with Bitcoin Core via RPC. Create, sign, and broadcast Bitcoin transactions, manage wallets, and access blockchain data through an easy-to-use API interface. Perfect for developers building cryptocurrency ap
66 lines (65 loc) • 3.04 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BitcoinCore = void 0;
const axios_1 = __importDefault(require("axios"));
const BlockchainRPC_1 = require("./BlockchainRPC");
const ControlRPC_1 = require("./ControlRPC");
const GeneratingRPC_1 = require("./GeneratingRPC");
const MiningRPC_1 = require("./MiningRPC");
const NetworkRPC_1 = require("./NetworkRPC");
const RawTransactionRPC_1 = require("./RawTransactionRPC");
const UtilRPC_1 = require("./UtilRPC");
const WalletRPC_1 = require("./WalletRPC");
class BitcoinCore {
constructor(config) {
this.config = config;
this.BlockchainRPC = new BlockchainRPC_1.BlockchainRPC(this);
this.ControlRPC = new ControlRPC_1.ControlRPC(this);
this.GeneratingRPC = new GeneratingRPC_1.GeneratingRPC(this);
this.MiningRPC = new MiningRPC_1.MiningRPC(this);
this.NetworkRPC = new NetworkRPC_1.NetworkRPC(this);
this.RawTransactionRPC = new RawTransactionRPC_1.RawTransactionRPC(this);
this.UtilRPC = new UtilRPC_1.UtilRPC(this);
this.WalletRPC = new WalletRPC_1.WalletRPC(this);
this.url = `http://${this.config.host}:${this.config.port}`;
}
callMethod(method_1) {
return __awaiter(this, arguments, void 0, function* (method, params = [], options) {
const auth = {
username: this.config.username,
password: this.config.password,
};
const url = (options === null || options === void 0 ? void 0 : options.wallet)
? `${this.url}/wallet/${options.wallet}`
: this.url;
// console.log(url);
try {
const response = yield axios_1.default.post(url, {
jsonrpc: '1.0',
id: 'curltest',
method: method,
params: params,
}, { auth });
// console.log('response', response);
return response.data;
}
catch (error) {
// console.log(error);
return error.response.data;
}
});
}
}
exports.BitcoinCore = BitcoinCore;