Skip to content

Instantly share code, notes, and snippets.

@makevoid
Created September 14, 2018 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makevoid/40036988ef6d89ca5f86ae5e210a8b56 to your computer and use it in GitHub Desktop.
Save makevoid/40036988ef6d89ca5f86ae5e210a8b56 to your computer and use it in GitHub Desktop.
NodeJS "core-client" module for interacting with Bitcoin Core via RPC
const CoreClient = require('bitcoin-core') // npm i --save bitcoinc-re
const host = '127.0.0.1' // ssh -L 8332:localhost:8332 root@YOUR_SERVER_IP -N # (ssh tunnel)
const core = new CoreClient({ // you have to
host: host,
username: 'bitcoin',
password: "PASSWORD",
})
;(async () => {
const coreInfo = await core.getInfo()
console.log(coreInfo)
const balance = await core.getBalance()
console.log(balance)
// all the methods listed in bitcoin-cli / bitcoin RPC documentation
// ... await core.methodName(...)
})()
// $ cat ~/.bitcoin/bitcoin.conf
//
// txindex=1
// rpcuser=bitcoin
// rpcpassword=PASSWORD
// dbcache=1500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment