Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blockchainjs

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blockchainjs

Bitcoin blockchain for wallets.

  • 0.3.12
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

blockchainjs

Version build status Coverage Status Dependency status

A pure JavaScript library for node.js and browsers for easy data exchange between wallets and bitcoin network.

What is include blockchainjs?

blockchainjs have two abstraction level: Connector and Blockchain

Connector implements a common interface for remote service. For now available only one provider: chromanode.

Blockchain implements a common interface between connector and your wallet. You can use Naive (trust all data from remove service) or Verified (SPV implementation).

In addition to Verified blockchainjs has Storage interface for store headers. Memory and LocalStorage available for now.

API

Examples

Show UTXO on address touched

var blockchainjs = require('blockchainjs')
var connector = new blockchainjs.connector.Chromanode({networkName: 'testnet'})
var address = 'mp8XoMWnJzQwovninMdChQutPuhyHokJNc'

function showUTXO(address) {
  connector.addressesQuery([address], {status: 'unspent'})
    .then(function (result) {
      console.log('UTXO for ' + address + ':')
      result.transactions.forEach(function (unspent) {
        // var txOut = unspent.txid + ':' + unspent.outIndex
        // console.log(txOut + ' has ' + unspent.value + ' satoshi')
        // sorry, only txid and height available now
        console.log('Unspent in txid: ' + unspent.txid)
      })
      if (result.transactions.length === 0) {
        console.log('nothing...')
      }
      console.log('')
    })
}

connector.on(address, showUTXO)
connector.connect()
connector.subscribe({event: 'touchAddress', address: address})
showUTXO(address)

Show last header upon completion of sync process

var blockchainjs = require('blockchainjs')

var connector = new blockchainjs.connector.Chromanode({networkName: 'testnet'})
connector.connect()

var storage = new blockchainjs.storage.Memory({
  networkName: 'testnet',
  compactMode: true
})

var blockchain = new blockchainjs.blockchain.Verified(connector, {
  storage: storage,
  networkName: 'testnet',
  testnet: true,
  compactMode: true,
  chunkHashes: blockchainjs.chunkHashes.testnet
})

blockchain.on('syncStop', blockchainjs.util.makeSerial(function () {
  return blockchain.getHeader(blockchain.latest.hash)
    .then(function (header) {
      console.log('Current header: ', header)
    })
}))

License

Code released under the MIT license.

Copyright 2015 Chromaway AB

Todo

Keywords

FAQs

Package last updated on 24 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc