@cryptech.services/bitcoin-rpc
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

GitHub license npm version GitHub last commit (branch) Node.js CI

bitcoin-rpc

A simple, efficient, zero-dep Bitcoin RPC interface.

Why?

Most other Bitcoin RPC libraries either:

  • Have unnecessary dependencies.
  • Don't follow proper standards (silent RPC errors, strange Promise handling, etc).
  • Have hardcoded RPC commands, meaning the lib must be upgraded every time the RPC daemon changes, seriously?

But why fork it?

TypeScript compilation allows the types to be easily exported, meaning that when the library updates, users of it won't have to update their types definitions manually in a separate file.

How?

import RPC from '@cryptech.services/bitcoin-rpc';

// Create a new RPC class for a Bitcoind RPC daemon
//                      user    pass      host      port
const btcRPC = new RPC('user', 'pass', '127.0.0.1', 8332);

// EXAMPLE: Fetch the latest block count
btcRPC.call('getblockcount').then((nBlocks) => {
  console.log("There's " + nBlocks + ' blocks in the blockchain, nice!');
});

// EXAMPLE: Fetch a raw block based on it's block hash
btcRPC
  .call(
    'getblock',
    '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'
  )
  .then((cBlock) => {
    console.log(cBlock);
  });

// EXAMPLE: Asynchronously fetch the latest block count
async function getBlockCount() {
  const nBlocks = await btcRPC.call('getblockcount');
  console.log("There's " + nBlocks + ' blocks in the blockchain, nice!');
}

Readme

Keywords

none

Package Sidebar

Install

npm i @cryptech.services/bitcoin-rpc

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

11.8 kB

Total Files

7

Last publish

Collaborators

  • ercknard
  • seqsee