2. Wallet Interaction

Import and generate Mnemonic

1
const Wallet = require('pugg-sdk');
2
const w = new Wallet();
3
w.importAccountFromMnemonic(
4
'tunnel penalty legal property alpha agree lyrics village canal biology cross select'
5
);
Copied!
Then you will be able to get something like the following
1
EthHdWallet {
2
_hdKey: EthereumHDKey {
3
_hdkey: HDKey {
4
versions: [Object],
5
depth: 0,
6
index: 0,
7
_privateKey: <Buffer 1d 7e e4 d9 92 7c 73 6b 25 e2 a3 15 60 2e 89 1e 86 31 f2 8c 5e 6f 10 64 60 2e 46 3c e4 6e 2d b2>,
8
_publicKey: <Buffer 03 d9 f8 9e e4 96 b7 ce 23 c4 c3 f0 af 75 37 d0 65 8d d9 18 5d cf c6 e8 eb 6f 61 98 08 54 d6 99 ac>,
9
chainCode: <Buffer 12 5c 73 a6 74 a2 c0 b0 88 80 c5 2f 6a c7 e9 aa 30 c0 ef e0 84 2b 9d b7 51 47 63 4c e8 69 25 9f>,
10
_fingerprint: 3540410809,
11
parentFingerprint: 0,
12
_identifier: <Buffer d3 06 61 b9 3b a3 ec 6a 4a 9e a7 a2 21 dc 6d 04 30 91 7f 1c>
13
}
14
},
15
_root: EthereumHDKey {
16
_hdkey: HDKey {
17
versions: [Object],
18
depth: 4,
19
index: 0,
20
_privateKey: <Buffer e4 63 07 d4 ff 77 83 e2 e6 fd f0 4c c3 04 a5 e4 df 12 ff 98 78 4e 71 c2 34 e6 7b ae d3 79 1e 24>,
21
_publicKey: <Buffer 02 86 5f c5 90 76 59 ad 38 06 49 f2 8f 5f 51 62 94 30 78 b5 8e f5 40 77 84 12 a1 64 8d d2 d3 da 51>,
22
chainCode: <Buffer e7 76 55 17 d7 2e 5a b3 3a b6 26 23 5c 6c a2 b8 a8 72 72 63 d6 30 d9 b5 3a 84 fe ff 56 8c a2 bc>,
23
_fingerprint: 1783838591,
24
parentFingerprint: 3504488862,
25
_identifier: <Buffer 6a 53 37 7f fb de 8c cc 31 36 8e 52 1a 0a 99 92 4f a9 03 6f>
26
}
27
},
28
_children: []
29
}
Copied!

Generate a new mnemonic

1
console.log(w.generateMnemonic());
Copied!
You will get this:
1
extend emerge win screen cash glare gravity proof space entry dynamic cash
Copied!

Get Private Key

1
const Wallet = require('pugg-sdk');
2
const w = new Wallet();
3
w.importAccountFromMnemonic(
4
'tunnel penalty legal property alpha agree lyrics village canal biology cross select'
5
);
6
console.log(w.getSelectedAccountPrivateKey());
Copied!
Then you will get this:
1
0x5648599257e21e66c393ccbac38a8e9e2676fd378efe987377ecfa1b433aae9c
Copied!