-
Notifications
You must be signed in to change notification settings - Fork 5
/
setupDashClient.js
73 lines (61 loc) · 2.23 KB
/
setupDashClient.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
const Dash = require('dash');
const dotenv = require('dotenv');
dotenv.config();
// Fully configured client options
const clientOptions = {
// The network to connect to ('testnet' or 'mainnet')
network: process.env.NETWORK,
// Wallet configuration for transactions and account management
wallet: {
// The mnemonic (seed phrase) for the wallet. Required for signing transactions.
mnemonic: process.env.MNEMONIC,
// Unsafe wallet options (use with caution)
unsafeOptions: {
// Starting synchronization from a specific block height can speed up the initial wallet sync process.
skipSynchronizationBeforeHeight: parseInt(
process.env.SYNC_START_HEIGHT,
10,
),
},
// The default account index to use for transactions and queries. Default is 0.
// defaultAccountIndex: 0,
},
// Configuration for Dash Platform applications
apps: {
// yourApp: { contractId: 'yourCustomAppContractId' },
tutorialContract: {
contractId: process.env.CONTRACT_ID, // Your contract ID
},
},
// Custom list of DAPI seed nodes to connect to. Overrides the default seed list.
// Format: { service: 'ip|domain:port' }
// seeds: [
// { host: 'seed-1.testnet.networks.dash.org:1443' }
// ],
// Custom list of DAPI addresses to connect to
// Format: [ 'ip:port' }
// dapiAddresses: [ '127.0.0.1:3000' ],
// Request timeout in milliseconds for DAPI calls
// timeout: 3000,
// The number of retries for a failed DAPI request before giving up
// retries: 5,
// The base ban time in milliseconds for a DAPI node that fails to respond properly
// baseBanTime: 120000,
};
/**
* Creates and returns a Dash client instance
* @returns {Dash.Client} The Dash client instance.
*/
const setupDashClient = () => {
// Ensure that numeric values from environment variables are properly converted to numbers
if (clientOptions.wallet?.unsafeOptions?.skipSynchronizationBeforeHeight) {
clientOptions.wallet.unsafeOptions.skipSynchronizationBeforeHeight =
parseInt(
clientOptions.wallet.unsafeOptions.skipSynchronizationBeforeHeight,
10,
);
}
// console.dir(clientOptions);
return new Dash.Client(clientOptions);
};
module.exports = setupDashClient;