-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcreate-wallet.mjs
More file actions
34 lines (29 loc) · 1.13 KB
/
create-wallet.mjs
File metadata and controls
34 lines (29 loc) · 1.13 KB
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
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/create-and-fund-a-wallet.html
import { wallet, PlatformAddressSigner, PrivateKey } from '@dashevo/evo-sdk';
const network = 'testnet';
try {
const mnemonic = await wallet.generateMnemonic();
const pathInfo =
network === 'testnet'
? await wallet.derivationPathBip44Testnet(0, 0, 0)
: await wallet.derivationPathBip44Mainnet(0, 0, 0);
// Derive the first BIP44 key to get a platform address
const keyInfo = await wallet.deriveKeyFromSeedWithPath({
mnemonic,
path: pathInfo.path,
network,
});
// Get the platform address (bech32m) from the private key
const privateKey = PrivateKey.fromWIF(keyInfo.toObject().privateKeyWif);
const signer = new PlatformAddressSigner();
const address = signer.addKey(privateKey).toBech32m(network);
// ⚠️ Never log mnemonics in real applications
console.log('Mnemonic:', mnemonic);
console.log('Platform address:', address);
console.log(
'Fund address using:',
`https://bridge.thepasta.org/?address=${address}`,
);
} catch (e) {
console.error('Something went wrong:', e.message);
}