Skip to content

A Node.js library for reading the bitcoin RPC configuration

License

Notifications You must be signed in to change notification settings

carnesen-archive/bitcoin-rpc-href

Repository files navigation

@carnesen/bitcoin-rpc-href npm version Build Status

A Node.js client for bitcoin's remote procedure call (RPC) interface. This package includes runtime JavaScript files suitable for Node.js >=8 as well as the corresponding TypeScript type declarations.

Usage

const { readRpcHref } = require('@carnesen/bitcoin-rpc-href');
const { URL } = require('url');

const href = readRpcHref();
// http://__cookie__:aaabbb@127.0.0.1:18443/

const url = new URL(href);
// URL {
//   href: 'http://__cookie__:aaabbb@127.0.0.1:18443/',
//   origin: 'http://127.0.0.1:18443',
//   protocol: 'http:',
//   username: '__cookie__',
//   password: 'aaabbb',
//   host: '127.0.0.1:18443',
//   hostname: '127.0.0.1',
//   port: '18443',
//   pathname: '/',
//   search: '',
//   searchParams: URLSearchParams {},
//   hash: '' }

API

readRpcHref(configFilePath?): href

Reads bitcoin configuration files to determine an "href" connection string for the RPC interface. The logic in this function is meant to reproduce as closely as possible that of the bitcoin-cli client that ships with the bitcoin server software. Among other things, if the configuration does not contain an rpcpassword, that means that "cookie-based" authentication is enabled. In that case readRpcHref reads the username and password from the rpccookiefile file written to datadir on startup.

configFilePath

Optional string. String path of a bitcoin configuration file. Default value is the platform-dependent location where bitcoin looks for its config file e.g. ~/.bitcoin/bitcoin.conf on Linux.

href

A string of the form http://<username>:<password>@<hostname>:<port>/ as defined by the WHATWG URL standard. The href can be passed to createBitcoinRpc to create an RPC client.

Related

License

MIT © Chris Arnesen

About

A Node.js library for reading the bitcoin RPC configuration

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published