2015-08-19 08:09:34 -07:00
# Bitcore v0.13
2014-12-23 05:23:51 -08:00
## Principles
2015-07-29 07:11:40 -07:00
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 provides a reliable API for JavaScript apps that need to interface with Bitcoin.
2014-12-23 05:23:51 -08:00
To get started, just `npm install bitcore` or `bower install bitcore` .
# Documentation Index
## Addresses and Key Management
* [Addresses ](address.md )
2015-01-20 12:56:39 -08:00
* [Using Different Networks ](networks.md )
2014-12-23 05:23:51 -08:00
* [Private Keys ](privatekey.md ) and [Public Keys ](publickey.md )
* [Hierarchically-derived Private and Public Keys ](hierarchical.md )
2015-01-20 12:56:39 -08:00
## Payment Handling
* [Using Different Units ](unit.md )
* [Acknowledging and Requesting Payments: Bitcoin URIs ](uri.md )
2014-12-23 05:23:51 -08:00
* [The Transaction Class ](transaction.md )
2015-01-20 12:56:39 -08:00
## Bitcoin Internals
2014-12-23 05:23:51 -08:00
* [Scripts ](script.md )
* [Block ](block.md )
## Extra
* [Crypto ](crypto.md )
* [Encoding ](encoding.md )
2014-12-29 08:20:22 -08:00
## Module Development
* [Browser Builds ](browser.md )
2015-01-20 12:56:39 -08:00
## Modules
2015-02-04 08:55:25 -08:00
Some functionality is implemented as a module that can be installed separately:
2015-01-20 12:56:39 -08:00
* [Payment Protocol Support ](https://github.com/bitpay/bitcore-payment-protocol )
2015-01-21 06:00:01 -08:00
* [Peer to Peer Networking ](https://github.com/bitpay/bitcore-p2p )
2015-01-20 12:56:39 -08:00
* [Bitcoin Core JSON-RPC ](https://github.com/bitpay/bitcoind-rpc )
* [Payment Channels ](https://github.com/bitpay/bitcore-channel )
* [Mnemonics ](https://github.com/bitpay/bitcore-mnemonic )
* [Elliptical Curve Integrated Encryption Scheme ](https://github.com/bitpay/bitcore-ecies )
* [Blockchain Explorers ](https://github.com/bitpay/bitcore-explorers )
2015-02-04 13:24:56 -08:00
* [Signed Messages ](https://github.com/bitpay/bitcore-message )
2015-01-20 12:56:39 -08:00
2014-12-23 05:23:51 -08:00
# Examples
2015-01-23 17:14:52 -08:00
## Create and Save a Private Key
2014-12-23 05:23:51 -08:00
2015-01-17 08:55:21 -08:00
```javascript
2015-01-23 17:14:52 -08:00
var privateKey = new bitcore.PrivateKey();
var exported = privateKey.toWIF();
// e.g. L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m
var imported = bitcore.PrivateKey.fromWIF(exported);
2015-01-28 08:10:06 -08:00
var hexa = privateKey.toString();
2015-01-27 05:12:04 -08:00
// e.g. 'b9de6e778fe92aa7edb69395556f843f1dce0448350112e14906efc2a80fa61a'
2014-12-23 05:23:51 -08:00
```
## Create an Address
2015-01-17 08:55:21 -08:00
```javascript
2015-01-23 17:14:52 -08:00
var address = privateKey.toAddress();
2014-12-23 05:23:51 -08:00
```
## Create a Multisig Address
2015-01-17 08:55:21 -08:00
```javascript
2014-12-23 05:23:51 -08:00
// Build a 2-of-3 address from public keys
2015-02-03 22:31:49 -08:00
var p2shAddress = new bitcore.Address([publicKey1, publicKey2, publicKey3], 2);
2014-12-23 05:23:51 -08:00
```
## Request a Payment
2015-01-17 08:55:21 -08:00
```javascript
2014-12-23 05:23:51 -08:00
var paymentInfo = {
address: '1DNtTk4PUCGAdiNETAzQFWZiy2fCHtGnPx',
amount: 120000 //satoshis
};
var uri = new bitcore.URI(paymentInfo).toString();
```
## Create a Transaction
2015-01-17 08:55:21 -08:00
```javascript
2014-12-23 05:23:51 -08:00
var transaction = new Transaction()
2014-12-23 08:18:25 -08:00
.from(utxos) // Feed information about what unspent outputs one can use
2014-12-23 05:23:51 -08:00
.to(address, amount) // Add an output with the given amount of satoshis
.change(address) // Sets up a change address where the rest of the funds will go
.sign(privkeySet) // Signs all the inputs it can
```
## Connect to the Network
2015-01-17 08:55:21 -08:00
```javascript
2014-12-23 05:23:51 -08:00
var peer = new Peer('5.9.85.34');
peer.on('inv', function(message) {
2014-12-23 08:18:25 -08:00
// new inventory
2014-12-23 05:23:51 -08:00
});
peer.connect();
```