-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathwallet_force_fee.js
85 lines (69 loc) · 2.41 KB
/
wallet_force_fee.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var blocktrail = require('../'); // require('blocktrail-sdk') when trying example from in your own project
var client = blocktrail.BlocktrailSDK({
apiKey : "MY_APIKEY",
apiSecret : "MY_APISECRET",
testnet : true
});
var sendTransaction = function(wallet) {
wallet.getNewAddress(function(err, address, path) {
if (err) {
return console.log("getNewAddress ERR", err);
}
console.log('new address', address, path);
var pay = {};
pay[address] = blocktrail.toSatoshi(0.001);
var options = {
forcefee: blocktrail.toSatoshi(0.00054321)
};
wallet.pay(pay, null, true, true, blocktrail.Wallet.FEE_STRATEGY_FORCE_FEE, null, options, function(err, result) {
if (err) {
return console.log("pay ERR", err);
}
console.log('transaction', result);
});
});
};
var action = 'default';
if (action === 'create') {
client.createNewWallet({
identifier: "example-wallet",
passphrase: "example-strong-password",
keyIndex: 9999
}, function(err, wallet, primaryMnemonic, backupMnemonic, blocktrailPubKeys) {
if (err) {
return console.log("createNewWallet ERR", err);
}
console.log('primary mnemonic', primaryMnemonic);
console.log('backup mnemonic', backupMnemonic);
console.log('blocktrail pubkeys', blocktrailPubKeys);
wallet.getNewAddress(function(err, address, path) {
if (err) {
return console.log("getNewAddress ERR", err);
}
console.log('new address', address, path);
});
});
} else {
client.initWallet({
identifier: "example-wallet",
readOnly: true
}, function(err, wallet) {
if (err) {
console.log('initWallet ERR', err);
throw err;
}
wallet.getBalance(function(err, confirmed, unconfirmed) {
if (err) {
return console.log("getBalance ERR", err);
}
console.log('confirmed balance', confirmed);
console.log('unconfirmed balance', unconfirmed);
wallet.unlock({passphrase: "example-strong-password"}, function(err) {
if (err) {
return console.log("unlock ERR", err);
}
sendTransaction(wallet);
});
});
});
}