1 | var blocktrail = require('../'); // require('blocktrail-sdk') when trying example from in your own project |
||
2 | |||
3 | var client = blocktrail.BlocktrailSDK({ |
||
4 | apiKey: process.env.BLOCKTRAIL_SDK_APIKEY || "EXAMPLE_BLOCKTRAIL_SDK_NODEJS_APIKEY", |
||
5 | apiSecret: process.env.BLOCKTRAIL_SDK_APISECRET || "EXAMPLE_BLOCKTRAIL_SDK_NODEJS_APISECRET", |
||
6 | testnet: true |
||
7 | }); |
||
8 | |||
9 | var randi = (Math.random() * 10000).toFixed(); |
||
10 | |||
11 | var passphrase = "example-strong-password"; |
||
12 | var walletVersion = blocktrail.Wallet.WALLET_VERSION_V2; |
||
13 | var identifier = "example-wallet-" + randi; |
||
14 | |||
15 | console.log("identifier: " + identifier); |
||
0 ignored issues
–
show
Debugging Code
introduced
by
![]() |
|||
16 | |||
17 | var getWallet = function() { |
||
18 | return client.createNewWallet({ |
||
19 | identifier: identifier, |
||
20 | passphrase: passphrase, |
||
21 | walletVersion: walletVersion, |
||
22 | keyIndex: 9999 |
||
23 | }) |
||
24 | .progress(function(p) { |
||
25 | console.log('progress', p); |
||
0 ignored issues
–
show
|
|||
26 | }) |
||
27 | .then(function(r) { |
||
28 | return r[0]; |
||
29 | }, function(e) { |
||
30 | if (e.message.match(/already exists/)) { |
||
31 | return client.initWallet({ |
||
32 | identifier: identifier, |
||
33 | passphrase: passphrase |
||
34 | }); |
||
35 | } else { |
||
36 | throw e; |
||
37 | } |
||
38 | }); |
||
39 | }; |
||
40 | |||
41 | getWallet() |
||
42 | .then(function(wallet) { |
||
43 | console.log('got wallet'); |
||
0 ignored issues
–
show
|
|||
44 | console.log(wallet.getAddressByPath("M/9999'/0/0")); |
||
45 | |||
46 | return wallet; |
||
47 | }) |
||
48 | .then(function(wallet) { |
||
49 | return wallet.upgradeToV3(passphrase) |
||
50 | .then(function() { |
||
51 | return wallet; |
||
52 | }); |
||
53 | }) |
||
54 | .then(function(wallet) { |
||
55 | console.log('UPGRADED!'); |
||
0 ignored issues
–
show
|
|||
56 | |||
57 | console.log(wallet.getAddressByPath("M/9999'/0/0")); |
||
58 | }) |
||
59 | .catch(function(e) { |
||
60 | console.log(e); |
||
0 ignored issues
–
show
|
|||
61 | throw e; |
||
62 | }) |
||
63 | .done(); |
||
64 |