-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·48 lines (48 loc) · 1.46 KB
/
index.js
File metadata and controls
executable file
·48 lines (48 loc) · 1.46 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env node
import { generateMnemonic, english, mnemonicToAccount } from 'viem/accounts';
import { bytesToHex } from 'viem';
function generateWallet() {
const mnemonic = generateMnemonic(english);
const account = mnemonicToAccount(mnemonic);
const walletInfo = {
mnemonic: mnemonic,
address: account.address,
privateKey: bytesToHex(account.getHdKey().privateKey)
};
console.log('Generated new wallet:');
console.log('Mnemonic:', walletInfo.mnemonic);
console.log('Address:', walletInfo.address);
console.log('Private Key:', walletInfo.privateKey);
return walletInfo;
}
function showHelp() {
console.log('Usage: evm-cli <command>');
console.log('');
console.log('Commands:');
console.log(' generate-wallet Generate a new Ethereum wallet');
console.log(' help Show this help message');
}
function main() {
const args = process.argv.slice(2);
const command = args[0];
switch (command) {
case 'generate-wallet':
generateWallet();
break;
case 'help':
case '--help':
case '-h':
showHelp();
break;
default:
if (!command) {
showHelp();
}
else {
console.error(`Unknown command: ${command}`);
console.error('Run "evm-cli help" for usage information.');
process.exit(1);
}
}
}
main();