Giter Site home page Giter Site logo

bitcoinjs-lib's Introduction

bitcoinjs-lib

Build Status

Browser Support

A pure JavaScript Bitcoin library for node.js and browsers. Backed by (slowly improving) testing, proven by over a million wallet users. The backbone for almost all Bitcoin web wallets in production today.

This is not the original bitcoinjs-lib that was not updated for a while. The current bitcoinjs-lib has been refactored to clean things up, add new functionality and merge improvements from the community. If you are looking for the original, it will be tagged as 0.1.3. We will use 0.2.x for releases based on these changes, so be sure to use the 0.1.3 tag if you need the original version.

Features

  • Bitcoin Testnet and Mainnet (production) support
  • HD Wallets
  • Highly secure random private key / address generation using window.crypto.getRandomValues
  • ECDSA signing and verification
  • Transaction creation (pay-to-pubkey-hash), support for multisignature transactions
  • A (somewhat incomplete) wallet implementation, improvements ongoing

Installation

npm install bitcoinjs-lib

Note: The npm version is currently out of date, are working to resolve this. The best way to use the latest code is to clone the repository.

Setup

Node.js

var bitcoin = require('bitcoinjs-lib')

From the repo:

var bitcoin = require('./src/index.js')

Browser

Compile bitcoinjs-min.js with the following command:

$ npm run-script compile

After loading this file in your browser, you will be able to use the global Bitcoin object.

Usage

These examples assume you are running bitcoinjs-lib in the browser.

Generating a Bitcoin address

key = Bitcoin.ECKey()

// Print your private key (used for signing transactions)
console.log(key.toString())
// => 5Jxfda2afuyMw3iaxzAwv6FvAs3XxmjV5y3GPAjZDEhRNJaFG5a

// Print your public key (Bitcoin address)
console.log(key.getPub().toString())
// => 18oxCAnbuKHDjP7KzLBDj8mLjggDBjE1Q9

Creating a Transaction

tx = new Bitcoin.Transaction()

// Add the input (the output of the previous transaction) of the form [previous transaction hash]:[index of the output to use]
tx.addInput("aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31:0")

// Add the output (who to pay to) of the form [payee's bitcoin address]:[amount in satoshis]
tx.addOutput("1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK:15000")

// Initialize the private key you created earlier so you can sign the transaction
key = Bitcoin.ECKey("5Jxfda2afuyMw3iaxzAwv6FvAs3XxmjV5y3GPAjZDEhRNJaFG5a")

// Sign the first input with your key
tx.sign(0, key)

// Print transaction serialized as hex. You can push the transaction onto the Bitcoin network manually
// here: https://blockchain.info/pushtx
console.log(tx.serializeHex())

Projects utilizing bitcoinjs-lib

Feel free to send pull requests to have your project/startup listed here.

Contributing

Instructions

  1. Fork the repo
  2. Push changes to your fork
  3. Create a pull request

Running the test suite

$ npm test

Alternatives

License

This library is free and open-source software released under the MIT license.

Copyright

BitcoinJS (c) 2011-2012 Stefan Thomas Released under MIT license http://bitcoinjs.org/

JSBN (c) 2003-2005 Tom Wu Released under BSD license http://www-cs-students.stanford.edu/~tjw/jsbn/

CryptoJS (c) 2009โ€“2012 by Jeff Mott Released under New BSD license http://code.google.com/p/crypto-js/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.