UNPKG

3.04 kBMarkdownView Raw
1# bsv v0.21.0
2
3## Principles
4
5Bitcoin 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.
6
7To get started, just `npm install bsv` or `bower install bsv`.
8
9# Documentation Index
10
11## Addresses and Key Management
12
13* [Addresses](address.md)
14* [Using Different Networks](networks.md)
15* [Private Keys](privatekey.md) and [Public Keys](publickey.md)
16* [Hierarchically-derived Private and Public Keys](hierarchical.md)
17
18## Payment Handling
19* [Using Different Units](unit.md)
20* [Acknowledging and Requesting Payments: Bitcoin URIs](uri.md)
21* [The Transaction Class](transaction.md)
22
23## Bitcoin Internals
24* [Scripts](script.md)
25* [Block](block.md)
26
27## Extra
28* [Crypto](crypto.md)
29* [Encoding](encoding.md)
30
31## Module Development
32* [Browser Builds](browser.md)
33
34## Modules
35
36Some functionality is implemented as a module that can be installed separately:
37
38* [Payment Protocol Support](https://github.com/bitpay/bsv-payment-protocol)
39* [Peer to Peer Networking](https://github.com/bitpay/bsv-p2p)
40* [Bitcoin Core JSON-RPC](https://github.com/bitpay/bitcoind-rpc)
41* [Payment Channels](https://github.com/bitpay/bsv-channel)
42* [Mnemonics](https://github.com/bitpay/bsv-mnemonic)
43* [Elliptical Curve Integrated Encryption Scheme](https://github.com/bitpay/bsv-ecies)
44* [Blockchain Explorers](https://github.com/bitpay/bsv-explorers)
45* [Signed Messages](https://github.com/bitpay/bsv-message)
46
47# Examples
48
49## Create and Save a Private Key
50
51```javascript
52var privateKey = new bsv.PrivateKey();
53
54var exported = privateKey.toWIF();
55// e.g. L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m
56var imported = bsv.PrivateKey.fromWIF(exported);
57var hexa = privateKey.toString();
58// e.g. 'b9de6e778fe92aa7edb69395556f843f1dce0448350112e14906efc2a80fa61a'
59```
60
61## Create an Address
62
63```javascript
64var address = privateKey.toAddress();
65```
66
67## Create a Multisig Address
68
69```javascript
70// Build a 2-of-3 address from public keys
71var p2shAddress = new bsv.Address([publicKey1, publicKey2, publicKey3], 2);
72```
73
74## Request a Payment
75
76```javascript
77var paymentInfo = {
78 address: '1DNtTk4PUCGAdiNETAzQFWZiy2fCHtGnPx',
79 amount: 120000 //satoshis
80};
81var uri = new bsv.URI(paymentInfo).toString();
82```
83
84## Create a Transaction
85
86```javascript
87var transaction = new Transaction()
88 .from(utxos) // Feed information about what unspent outputs one can use
89 .to(address, amount) // Add an output with the given amount of satoshis
90 .change(address) // Sets up a change address where the rest of the funds will go
91 .sign(privkeySet) // Signs all the inputs it can
92```
93
94## Connect to the Network
95
96```javascript
97var peer = new Peer('5.9.85.34');
98
99peer.on('inv', function(message) {
100 // new inventory
101});
102
103peer.connect();
104```