bitcoin-rpc-api

0.0.5 • Public • Published

bitcoin-rpc-api

A modern full-featured Bitcoin Core REST and RPC Express middleware to execute administrative tasks, multiwallet operations and queries about network and the blockchain using URL structure exposed for easy interfacing with a bitcoind Bitcoin wallet..

Status

NPM Package Build Status

Installation

Install the package via npm:

npm install bitcoin-rpc-api --save

Usage

Examples

Using Node.js

Example of a setup
var bitcoin = require('bitcoin-rpc-api');
var express = require('express');
var app = express();
 
//Username and password relate to those set in the bitcoin.conf file
 
var node = {
  protocol: 'http',
  host: 'localhost',
  port: 8332,
  user: 'username',
  pass: 'password'
};
 
bitcoin.setup(node);
app.use('/bitcoin', bitcoin.api); //Bind the middleware to any chosen url
 
app.listen(3000);

Client/Browser

Just add the method name after the binded url.

For example:

This will return data as expected from bitcoin-cli

{
  "chain": "main",
  "blocks": 559438,
  "headers": 559438,
  "bestblockhash": "",
  "difficulty": 5883988430955.408,
  "mediantime": 1548061269,
  "verificationprogress": 0.9999991510791459,
  "initialblockdownload": false,
  "chainwork": "",
  "size_on_disk": 548902880,
  "pruned": true,
  "prune_target_size": 576716800,
  "softforks": [ ... ],
  "bip9_softforks": {
    "csv": { ... },
    "segwit": { ... }
  },
  "warnings": ""
}
 
 

Parameters should be sent via a query string:

Client(...args)

Params

The command sh bitcoin-cli validateaddress "1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc" can be converted as

This will return in similar faishon.

  { 
    "result": {
      "isvalid": true,
      "address": "1N2xxpqDDPb1wm",
      "scriptPubKey": "76a914e6b9c5ba5d75088ac",
      "ismine": false,
      "iswatchonly": false,
      "isscript": false,
      "iswitness": false
    },
    "error": null,
    "id": null
  }
  

Consult the API list for parameter information.

More APIs with complex params coming soon...

.walletPass(passphrase);

If your wallet is encrypted set that before using middleware. Ex:

bitcoin.setup(wallet);
bitcoin.walletPass("passwordorpassphrase");
app.use('/bitcoin/api', bitcoin.api);

Projects

Bitcoin-RPC-Api is used in the following projects:

If you use Bitcoin-RPC-Api in your projects submit a pull request to the readme with a link or send me an email: dibyanshu.sunny@gmail.com

Licence

Code released under the MIT license.

Copyright (C) 2019 Dibyanshu

Package Sidebar

Install

npm i bitcoin-rpc-api

Weekly Downloads

2

Version

0.0.5

License

MIT

Unpacked Size

11 kB

Total Files

5

Last publish

Collaborators

  • dibyanshu