Bitcoin wallet script
A pure JavaScript Bitcoin library for node.js and browsers. Used in production by over 1.5 million wallet users, BitcoinJS is the backbone for almost all Bitcoin web wallets in production today.
- Clean - Pure JavaScript, concise code, easy to read.
- Tested - Coverage > 95%, third-party integration tests.
- Careful - Two person approval process for small, focused pull requests.
- Compatible - Works on Node.js and all modern browsers.
- Powerful - Support for advanced features, such as multi-sig, HD Wallets.
- Secure - Strong random number generation, PGP signed releases, trusted developers.
- Principled - No support for browsers with crap RNG (IE
- Experiment-friendly - Bitcoin Mainnet and Testnet support.
* directly contributed code or funding to the project.
Your bankpossibly your bank.
Install via NPM:
$ npm install bitcoinjs-lib
Compile for browser:
$ npm install bitcoinjs-lib browserify uglify-js $ browserify -r bitcoinjs-lib -s bitcoin | uglifyjs > bitcoinjs.min.js
Source code:
Latest warning: master branch is unstable! Only use releases in production.
Generating a Bitcoin address:
var keyPair = bitcoin.ECPair.makeRandom // Print your private key (in WIF format) console.log(keyPair.toWIF) // => Kxr9tQED9H44gCmp6HAdmemAzU3n84H3dGkuWTKvE23JgHMW8gct // Print your public key address console.log(keyPair.getAddress) // => 14bZ7YWde4KdRb5YN7GYkToz3EHVCvRxkF
Creating a Transaction
var tx = new bitcoin.TransactionBuilder // Add the input (who is paying): // [previous transaction hash, index of the output to use] var txId = 'aa94ab02c182214f090e99a0d57021caffd0f12b1028b130b63e31' tx.addInput(txId, 0) // Add the output (who to pay to): // [payee's address, amount in satoshis] tx.addOutput("1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK", 15000) // Initialize a private key using WIF var privateKeyWIF = 'L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy' var keyPair = bitcoin.ECPair.fromWIF(privateKeyWIF) // Sign the first input with the new key tx.sign(0, keyPair) // Print transaction serialized as hex console.log(tx.build.toHex) // => 313eb630b11ca895f1d0ffca21 ... // You could now push the transaction onto the Bitcoin network manually // (see
We provide extensive code testing as a reference that shows what the code is proven to do. There are no plans for written documentation, but you are welcome to contribute some.
Stefan Thomas is the inventor and creator of this project. His pioneering work made Bitcoin web wallets possible.
Daniel Cousens, Wei Lu, JP Richardson and Kyle Drake led the major refactor of the library from 0.1.3 to 1.0.0.
We always welcome help on the library. If you want to help build (or fix bugs), fork the repository, create a topic branch (keep it focused, and ADD TESTS), make the change, commit to your forked repo, and send a pull request.