1 | # BitGo Javascript SDK
|
2 |
|
3 | The BitGo Platform and SDK makes it easy to build multi-signature crypto-currency applications today with support for Bitcoin, Ethereum and many other coins.
|
4 | The SDK is fully integrated with the BitGo co-signing service for managing all of your BitGo wallets.
|
5 |
|
6 | Included in the SDK are examples for how to use the API to manage your multi-signature wallets.
|
7 |
|
8 | Please email us at support@bitgo.com if you have questions or comments about this API.
|
9 |
|
10 | [![Known Vulnerabilities](https://snyk.io/test/npm/bitgo/badge.svg)](https://snyk.io/test/npm/bitgo) [![Build Status](https://cloud.drone.io/api/badges/BitGo/BitGoJS/status.svg)](https://cloud.drone.io/BitGo/BitGoJS)
|
11 |
|
12 | # Installation
|
13 |
|
14 | Please make sure you are running at least Node version 8 (the latest LTS release is recommended) and NPM version 6.
|
15 | We recommend using `nvm`, the [Node Version Manager](https://github.com/creationix/nvm/blob/master/README.markdown#installation), for setting your Node version.
|
16 |
|
17 | `npm install --save bitgo`
|
18 |
|
19 | # Full Documentation
|
20 |
|
21 | Please see our [SDK Documentation](https://bitgo-sdk-docs.s3.amazonaws.com/core/11.3.0/index.html) for detailed information about the Typescript SDK and functionality.
|
22 |
|
23 | For more general information about the BitGo API, please see our [REST API Documentation](https://www.bitgo.com/api/v2).
|
24 |
|
25 | # Release Notes
|
26 |
|
27 | You can find the complete release notes (since version 4.44.0) [here](https://github.com/BitGo/BitGoJS/blob/master/modules/core/RELEASE_NOTES.md).
|
28 |
|
29 | # Example Usage
|
30 |
|
31 | ## Initialize SDK
|
32 | Create an access token by logging into your bitgo account, going to the API access tab [in the settings area](https://www.bitgo.com/settings) and making a developer token.
|
33 | ```js
|
34 | const BitGo = require('bitgo');
|
35 | const bitgo = new BitGo.BitGo({ accessToken: ACCESS_TOKEN }); // defaults to testnet. add env: 'prod' if you want to go against mainnet
|
36 | const result = await bitgo.session();
|
37 | console.dir(result);
|
38 | ```
|
39 |
|
40 | ## Create Wallet
|
41 | ```js
|
42 | const params = {
|
43 | "passphrase": "replaceme",
|
44 | "label": "firstwallet"
|
45 | };
|
46 | const { wallet } = await bitgo.coin('tbtc').wallets().generateWallet(params);
|
47 | console.dir(wallet);
|
48 | ```
|
49 |
|
50 | ## Create new address
|
51 | ```js
|
52 | const address = await wallet.createAddress();
|
53 | console.dir(address);
|
54 | ```
|
55 |
|
56 | ## View wallet transfers
|
57 | ```js
|
58 | const transfers = await wallet.transfers();
|
59 | ```
|
60 |
|
61 | ## Send coins
|
62 | ```js
|
63 | const result = await wallet.sendCoins({
|
64 | address: "2NEe9QhKPB2gnQLB3hffMuDcoFKZFjHYJYx",
|
65 | amount: 0.01 * 1e8,
|
66 | walletPassphrase: "replaceme"
|
67 | });
|
68 | console.dir(result);
|
69 | ```
|
70 |
|
71 | ## More examples
|
72 | Further demos and examples in both Javascript and Typescript can be found in the [example](example) directory.
|
73 |
|
74 | # Enabling additional debugging output
|
75 |
|
76 | `bitgo` uses the `debug` package to emit extra information, which can be useful when debugging issues with BitGoJS or BitGo Express.
|
77 |
|
78 | When using the `bitgo` npm package, the easiest way to enable debug output is by setting the `DEBUG` environment variable to one or more of the debug namespaces in the table below. Multiple debug namespaces can be enabled by giving a comma-separated list or by using `*` as a wildcard. See the [debug package documentation](https://github.com/visionmedia/debug#readme) for more details.
|
79 |
|
80 | ## Available Debug Namespaces
|
81 | | Namespace | Description |
|
82 | | --- | --- |
|
83 | | `bitgo:index` | Core BitGo object. Currently only constant fetch failures and HMAC response failures will emit debug information for this namespace. |
|
84 | | `bitgo:v1:txb` | Version 1 (legacy) transaction builder |
|
85 | | `bitgo:v2:pendingapprovals` | Pending approval operations. Currently only wallet fetch errors will emit debug information for this namespace. |
|
86 | | `bitgo:v2:wallet` | Wallet operations including transaction prebuild, sendMany calls and consolidation transactions |
|
87 | | `bitgo:v2:utxo` | Low level operations for UTXO coins, including transaction parsing, verification, signing and explanations |
|
88 | | `bitgo:v2:eth` | Ethereum specific output. Currently only failures to require the optional Ethereum libraries are reported |
|
89 | | `bitgo:v2:util` | SDK utilities specific output. Currently only failures to require the optional Ethereum libraries are reported |
|
90 |
|
91 | Another debug namespace which is not provided by BitGoJS but is helpful nonetheless is the `superagent` namespace, which will output all HTTP requests and responses (only the URL, not bodies).
|
92 |
|
93 | ## Example
|
94 |
|
95 | To run an SDK script with debug output enabled, export the DEBUG environment variable before running.
|
96 | ```shell script
|
97 | export DEBUG='bitgo:*' # enable all bitgo debug namespaces
|
98 | node myScript.js
|
99 | ```
|
100 |
|
101 | To set debug namespaces in the browser, you should set `localStorage.debug` property instead of the `DEBUG` environment variable using your browser's development tools console.
|
102 |
|
103 | ```js
|
104 | localStorage.debug = 'bitgo:*'; // enable all bitgo debug namespaces
|
105 | ```
|
106 |
|
107 | # Using with Typescript
|
108 |
|
109 | `bitgo` is not yet compatible with the `noImplicitAny` compiler option. If you want to use this option in your project (and we recommend that you do), you must set the `skipLibCheck` option to supress errors about missing type definitions for dependencies of `bitgo`.
|
110 |
|
111 | # Usage in Browser
|
112 |
|
113 | Since version 6, `bitgo` includes a minified, browser-compatible bundle by default at `dist/browser/BitGoJS.min.js`. It can be copied from there directly into your project.
|
114 |
|
115 | BitGoJS can also be bundled with any module bundler. There is a Webpack configuration file already included, which can be triggered with package scripts.
|
116 |
|
117 | For a production build: `npm run-script compile`
|
118 |
|
119 | For a development (non-minified) build: `npm run-script compile-dbg`
|
120 |
|
121 | To build the test suite into a single test file: `npm run-script compile-test`
|