-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
62 changed files
with
1,504 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
title: Browser Builds | ||
description: Guide to writing modules and optimizing browser bundles. | ||
--- | ||
|
||
# Browser Builds | ||
|
||
When developing a module that will need to work in a browser and does not use the entire Bitcore namespace, it's recommended to narrow the scope of the requires to the particular modules that are needed. It will produce a smaller browser bundle as it will only include the JavaScript that is nessessary. Below is a quick tutorial that will use three modules. | ||
|
||
## Tutorial | ||
|
||
**Step 1**: Require Bitcore Modules | ||
|
||
Here we require specific Bitcore modules that will be used in a `index.js` file: | ||
|
||
```javascript | ||
|
||
var PrivateKey = require('bitcore/lib/privatekey'); | ||
var PublicKey = require('bitcore/lib/publickey'); | ||
var Address = require('bitcore/lib/address'); | ||
|
||
// the rest of the module here | ||
|
||
``` | ||
|
||
**Step 2**: Browserifying | ||
|
||
Next we will generate a browser bundle using [browserify](https://www.npmjs.com/package/browserify) by running the command: | ||
|
||
```bash | ||
browserify index.js -o index.browser.js | ||
``` | ||
|
||
This will output a file `index.browser.js` at around 700KB *(the entire Bitcore namespace is around 2MB)*. | ||
|
||
**Step 3**: Uglifying | ||
|
||
This can be further optimized by using [uglifyjs](https://www.npmjs.com/package/uglify-js), and running the command: | ||
|
||
```bash | ||
uglifyjs index.browser.js --compress --mangle -o index.browser.min.js | ||
``` | ||
|
||
The resulting file `index.browser.min.js` in this case should be less than 300KB. | ||
|
||
## Modules | ||
|
||
Here is a list of some of the common modules: | ||
|
||
```javascript | ||
var Address = require('bitcore/lib/address'); | ||
var Block = require('bitcore/lib/block'); | ||
var BlockHeader = require('bitcore/lib/blockheader'); | ||
var HDPrivateKey = require('bitcore/lib/hdprivatekey'); | ||
var HDPublicKey = require('bitcore/lib/hdpublickey'); | ||
var PaymentProtocol = require('bitcore/lib/paymentprotocol'); | ||
var PrivateKey = require('bitcore/lib/privatekey'); | ||
var PublicKey = require('bitcore/lib/publickey'); | ||
var Script = require('bitcore/lib/script'); | ||
var Transaction = require('bitcore/lib/transaction'); | ||
var URI = require('bitcore/lib/uri'); | ||
var Unit = require('bitcore/lib/unit'); | ||
``` | ||
|
||
For more informatation about each of the modules please see the [Bitcore Documentation](index.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
title: Insight Explorer | ||
description: Provides an interface to fetch information about the state of the blockchain from a trusted Insight server. | ||
--- | ||
# Insight | ||
|
||
## Description | ||
|
||
`bitcore.transport.explorers.Insight` is a simple agent to perform queries to an Insight blockchain explorer. The default servers are `https://insight.bitpay.com` and `https://test-insight.bitpay.com`, hosted by BitPay Inc. You can (and we strongly suggest you do) run your own insight server. For more information, head to https://github.com/bitpay/insight-api | ||
|
||
There are currently two methods implemented (the API will grow as features are requested): `getUnspentUtxos` and `broadcast`. | ||
|
||
### Retrieving Unspent UTXOs for an Address (or set of) | ||
|
||
```javascript | ||
var insight = new Insight(); | ||
insight.getUnspentUtxos('1Bitcoin...', function(err, utxos) { | ||
if (err) { | ||
// Handle errors... | ||
} else { | ||
// Maybe use the UTXOs to create a transaction | ||
} | ||
}); | ||
``` | ||
|
||
### Broadcasting a Transaction | ||
|
||
```javascript | ||
var insight = new Insight(); | ||
insight.broadcast(tx, function(err, returnedTxId) { | ||
if (err) { | ||
// Handle errors... | ||
} else { | ||
// Mark the transaction as broadcasted | ||
} | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.