-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcreate-wallet.js
36 lines (30 loc) · 1.12 KB
/
create-wallet.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
// See https://dashplatform.readme.io/docs/tutorial-create-and-fund-a-wallet
const Dash = require('dash');
const dotenv = require('dotenv');
dotenv.config();
const clientOpts = {
network: process.env.NETWORK,
wallet: {
mnemonic: null, // this indicates that we want a new wallet to be generated
// if you want to get a new address for an existing wallet
// replace 'null' with an existing wallet mnemonic
offlineMode: true, // this indicates we don't want to sync the chain
// it can only be used when the mnemonic is set to 'null'
},
};
const client = new Dash.Client(clientOpts);
const createWallet = async () => {
const account = await client.getWalletAccount();
const mnemonic = client.wallet.exportWallet();
const address = account.getUnusedAddress();
console.log('Mnemonic:', mnemonic);
console.log('Unused address:', address.address);
};
createWallet()
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
// Handle wallet async errors
client.on('error', (error, context) => {
console.error(`Client error: ${error.name}`);
console.error(context);
});