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