is supported by BitPay
View on GitHub

A pure, powerful core for your bitcoin project.

Get Started

Principles

Bitcoin is a powerful new peer-to-peer platform for the next generation of financial technology. The decentralized nature of the Bitcoin network allows for highly resilient bitcoin infrastructure, and the developer community needs reliable, open-source tools to implement bitcoin apps and services.

Bitcore unchains developers from fallible, centralized APIs, and provides the tools to interact with the real Bitcoin network.

Get Started

Bitcore runs on node, and can be installed via npm:

npm install bitcore

It is a collection of objects useful to bitcoin applications, such as Address:

var bitcore = require('bitcore');
var Address = bitcore.Address;

If you're feeling experimental, you can get the latest master from our github repo:

git clone git://github.com/bitpay/bitcore

Browser version

Download the browser bundle, or build a custom one by acquiring the source code.

Note: If you clone the github repository, you can also generate the bundle yourself.

Run all bitcore tests in your browser

Live Demo

Examples

Validating a bitcoin address.

var bitcore = require('bitcore');
var Address = bitcore.Address;

var addr = new Address("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa");

console.log(addr.isValid());

Monitoring blocks and transactions. For this example you need a running bitcoind instance with RPC enabled.

var bitcore = require('bitcore');
var networks = bitcore.networks;
var Peer = bitcore.Peer;
var PeerManager = require('soop').load('bitcore/PeerManager', {
  network: networks.testnet
});

var handleBlock = function(info) {
  console.log('** Block Received **');
  console.log(info.message);
};

var handleTx = function(info) {
  var tx = info.message.tx.getStandardizedObject();

  console.log('** TX Received **');
  console.log(tx);
};

var handleInv = function(info) {
  console.log('** Inv **');
  console.log(info.message);

  var invs = info.message.invs;
  info.conn.sendGetData(invs);
};

var peerman = new PeerManager();

peerman.addPeer(new Peer('127.0.0.1', 18333));

peerman.on('connection', function(conn) {
  conn.on('inv', handleInv);
  conn.on('block', handleBlock);
  conn.on('tx', handleTx);
});

peerman.start();

Consuming a bitcoind RPC. For this example you need a running bitcoind instance with RPC enabled.

var bitcore = require('bitcore');
var RpcClient = bitcore.RpcClient;
var hash = '0000000000b6288775bbd326bedf324ca8717a15191da58391535408205aada4';

var config = {
  protocol: 'http',
  user: 'user',
  pass: 'pass',
  host: '127.0.0.1',
  port: '18332',
};

var rpc = new RpcClient(config);

rpc.getBlock(hash, function(err, ret) {
  if (err) {
    console.error('An error occured fetching block', hash);
    console.error(err);
    return;
  }
  console.log(ret);
});

Creating and sending a Transaction through P2P.

var bitcore = require('bitcore');
var networks = bitcore.networks;
var Peer = bitcore.Peer;
var Transaction = bitcore.Transaction;
var Address = bitcore.Address;
var Script = bitcore.Script;
var coinUtil = bitcore.util;
var PeerManager = require('soop').load('bitcore/PeerManager', {
  network: networks.testnet
});

var createTx = function() {
  var TXIN = 'd05f35e0bbc495f6dcab03e599c8f5e32a07cdb4bc76964de201d06a2a7d8265';
  var TXIN_N = 0;
  var ADDR = 'muHct3YZ9Nd5Pq7uLYYhXRAxeW4EnpcaLz';
  var VAL = '0.001';

  var txobj = {
    version: 1,
    lock_time: 0,
    ins: [],
    outs: []
  };

  var txin = {
    s: coinUtil.EMPTY_BUFFER, // Add signature
    q: 0xffffffff
  };

  var hash = new Buffer(TXIN.split('').reverse(), 'hex');
  var vout = parseInt(TXIN_N);
  var voutBuf = new Buffer(4);

  voutBuf.writeUInt32LE(vout, 0);
  txin.o = Buffer.concat([hash, voutBuf]);
  txobj.ins.push(txin);

  var addr = new Address(ADDR);
  var script = Script.createPubKeyHashOut(addr.payload());
  var valueNum = coinUtil.parseValue(VAL);
  var value = coinUtil.bigIntToValue(valueNum);

  var txout = {
    v: value,
    s: script.getBuffer(),
  };
  txobj.outs.push(txout);

  return new Transaction(txobj);

};

var peerman = new PeerManager();
peerman.addPeer(new Peer('127.0.0.1', 18333));

peerman.on('connect', function() {
  var conn = peerman.getActiveConnection();
  if (conn) {
    conn.sendTx(createTx());
  }
  conn.on('reject', function() {
    console.log('Transaction Rejected');
  });
});

peerman.start();

Parsing a script.

var bitcore = require('bitcore');
var Address = bitcore.Address;
var coinUtil = bitcore.util;
var Script = bitcore.Script;
var network = bitcore.networks.testnet;

var getAddrStr = function(s) {
  var addrStrs = [];
  var type = s.classify();
  var addr;

  switch (type) {
    case Script.TX_PUBKEY:
      var chunk = s.captureOne();
      addr = new Address(network.addressPubkey, coinUtil.sha256ripe160(chunk));
      addrStrs.push(addr.toString());
      break;
    case Script.TX_PUBKEYHASH:
      addr = new Address(network.addressPubkey, s.captureOne());
      addrStrs.push(addr.toString());
      break;
    case Script.TX_SCRIPTHASH:
      addr = new Address(network.addressScript, s.captureOne());
      addrStrs.push(addr.toString());
      break;
    case Script.TX_MULTISIG:
      var chunks = s.capture();
      chunks.forEach(function(chunk) {
        var a = new Address(network.addressPubkey, coinUtil.sha256ripe160(chunk));
        addrStrs.push(a.toString());
      });
      break;
    case Script.TX_UNKNOWN:
      console.log('tx type unkown');
      break;
  }
  return addrStrs;
};

var script = 'DUP HASH160 0x14 0x3744841e13b90b4aca16fe793a7f88da3a23cc71 EQUALVERIFY CHECKSIG';
var s = Script.fromHumanReadable(script);
console.log(getAddrStr(s)[0]); // mkZBYBiq6DNoQEKakpMJegyDbw2YiNQnHT

Security

Bitcore is still under heavy development and not quite ready for "drop-in" production use. If you find a security issue, please email ryan at bitpay dot com.

Contributing

Bitcore is under active development by BitPay engineers and volunteers from all over the world. We deeply appreciate feedback, issues, and pull requests, all of which can be done on the GitHub page. We also have an IRC channel, if that's your style. #bitcore on Freenode.

Projects Using Bitcore