soluser 1.0.3 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@ npm install -g soluser@latest
7
7
  ```shell
8
8
  $ soluser new charlie
9
9
  $ soluser new alice --word-length 12
10
- $ soluser new bob --word-length 24 --no-bip39-passphrase
10
+ $ soluser new bob --word-length 24 --without-passphrase
11
11
  ```
12
12
 
13
13
  ## 切换账号
@@ -25,3 +25,23 @@ $ soluser list
25
25
  $ soluser remove alice
26
26
  ```
27
27
 
28
+ ## 查看alias对应的地址
29
+ ```shell
30
+ $ soluser address alice
31
+ ```
32
+
33
+ ## 查看alias对应的余额
34
+ ```shell
35
+ $ soluser balance alice
36
+ ```
37
+
38
+ ## airdrop 给alias
39
+ ```shell
40
+ $ soluser airdrop 5 alice
41
+ Requesting airdrop of 5 SOL
42
+
43
+ Signature: 4BLUt5uxutbEwVywBTbAoBnG4EKb6QgsHgk3JRfjy6uJCoNjxdyYodbAhsWPXquBBwVzui1WyQxKn9d39JnwS3Pb
44
+
45
+ 500000005 SOL
46
+ ```
47
+
package/bin/index.js CHANGED
@@ -6,6 +6,45 @@ const switchAccount = require('../src/commands/switch');
6
6
  const listAccounts = require('../src/commands/list');
7
7
  const removeAccount = require('../src/commands/remove');
8
8
 
9
+ // 导入地址查询命令
10
+ const showAddress = require('../src/commands/address');
11
+ // 导入余额查询命令
12
+ const checkBalance = require('../src/commands/balance');
13
+ // Import the airdrop command
14
+ const requestAirdrop = require('../src/commands/airdrop');
15
+
16
+
17
+
18
+ // 定义地址查询命令
19
+ program
20
+ .command('address')
21
+ .description('Output the base58 address of a Solana account')
22
+ .argument('<alias>', 'Alias of the account to get address') // 接收别名作为位置参数
23
+ .action((alias) => {
24
+ showAddress(alias);
25
+ });
26
+
27
+
28
+ // Define the airdrop command
29
+ program
30
+ .command('airdrop')
31
+ .description('Request an airdrop of SOL to a Solana account')
32
+ .argument('<amount>', 'Amount of SOL to request')
33
+ .argument('<alias>', 'Alias of the account to receive the airdrop')
34
+ .action((amount, alias) => {
35
+ requestAirdrop(amount, alias);
36
+ });
37
+
38
+ // ... existing code ...
39
+ // 定义余额查询命令
40
+ program
41
+ .command('balance')
42
+ .description('Check the SOL balance of a Solana account')
43
+ .argument('<alias>', 'Alias of the account to check balance') // 接收别名作为位置参数
44
+ .action((alias) => {
45
+ checkBalance(alias);
46
+ });
47
+
9
48
 
10
49
  // 定义新建账号命令
11
50
  // 定义新建账号命令(修改后)
package/package.json CHANGED
@@ -1,21 +1,23 @@
1
1
  {
2
- "name": "soluser",
3
- "version": "1.0.3",
2
+ "name": "soluser",
3
+ "version": "1.0.6",
4
4
  "description": "A CLI tool to manage Solana accounts (new, switch, list)",
5
- "main": "bin/index.js",
5
+ "main": "bin/index.js",
6
6
  "bin": {
7
7
  "soluser": "./bin/index.js"
8
8
  },
9
- "keywords": ["solana", "cli", "account", "wallet"],
9
+ "keywords": [
10
+ "solana",
11
+ "cli",
12
+ "account",
13
+ "wallet"
14
+ ],
10
15
  "author": "guahuzi",
11
- "license": "MIT",
16
+ "license": "MIT",
12
17
  "dependencies": {
13
- "commander": "^11.1.0",
14
- "cli-table3": "^0.6.3"
15
18
  },
16
19
  "repository": {
17
20
  "type": "git",
18
21
  "url": "https://github.com/nextuser/soluser.git"
19
22
  }
20
23
  }
21
-
@@ -0,0 +1,22 @@
1
+ const { existsAccount, getKeyFilePath } = require('../utils/path');
2
+ const { getAddress } = require('../utils/solana');
3
+
4
+ function showAddress(alias) {
5
+ // 1. 检查账号是否存在
6
+ if (!existsAccount(alias)) {
7
+ console.error(`Error: Account "${alias}" does not exist.`);
8
+ console.error(` Use "soluser list" to view all available accounts.`);
9
+ process.exit(1);
10
+ }
11
+
12
+ // 2. 解析并输出 base58 地址
13
+ try {
14
+ const address = getAddress(alias); // 复用之前的 getAddress 函数(基于 solana-keygen)
15
+ process.stdout.write(address); // 直接输出地址(方便脚本调用)
16
+ } catch (err) {
17
+ console.error(`Error: Failed to parse address for "${alias}": ${err.message}`);
18
+ process.exit(1);
19
+ }
20
+ }
21
+
22
+ module.exports = showAddress;
@@ -0,0 +1,20 @@
1
+ // src/commands/airdrop.js
2
+ const { execCommand } = require('../utils/solana');
3
+ const { getAddress } = require('../utils/solana');
4
+ function requestAirdrop(amount, alias) {
5
+
6
+
7
+ try {
8
+ const address = getAddress(alias);
9
+ // Execute the solana airdrop command with the amount and resolved address
10
+ const cmd = `solana airdrop ${amount} ${address}`;
11
+ const result = execCommand(cmd);
12
+ console.log(result);
13
+ } catch (error) {
14
+ console.log("eroror in call requestAirdrop ${amount} ${alias}");
15
+ console.error(`Failed to request airdrop: ${error.message} \n `);
16
+ process.exit(1);
17
+ }
18
+ }
19
+
20
+ module.exports = requestAirdrop;
@@ -0,0 +1,33 @@
1
+ const { existsAccount } = require('../utils/path');
2
+ const { getAddress, execCommand } = require('../utils/solana');
3
+
4
+ function checkBalance(alias) {
5
+ // 1. 检查账号是否存在
6
+ if (!existsAccount(alias)) {
7
+ console.error(`Error: Account "${alias}" does not exist.`);
8
+ console.error(` Use "soluser list" to view all available accounts.`);
9
+ process.exit(1);
10
+ }
11
+
12
+ // 2. 获取账号对应的公钥(address)
13
+ let address;
14
+ try {
15
+ address = getAddress(alias);
16
+ } catch (err) {
17
+ console.error(`Error: Failed to get address for "${alias}": ${err.message}`);
18
+ process.exit(1);
19
+ }
20
+
21
+ // 3. 调用 solana balance 命令查询余额
22
+ try {
23
+ // solana balance 命令会返回类似 "1.2345 SOL" 的结果
24
+ const balance = execCommand(`solana balance ${address}`);
25
+ console.log(`${alias}: ${balance}`); // 输出格式:别名 + 余额
26
+ } catch (err) {
27
+ console.error(`Error: Failed to check balance for "${alias}": ${err.message}`);
28
+ console.error(` Ensure Solana CLI is configured with a valid network (e.g., "solana config set --url https://api.devnet.solana.com")`);
29
+ process.exit(1);
30
+ }
31
+ }
32
+
33
+ module.exports = checkBalance;
@@ -26,7 +26,7 @@ function listAccounts() {
26
26
  // 3. 构建表格
27
27
  const table = new Table({
28
28
  head: ['alias', 'address', 'active'],
29
- colWidths: [15, 45, 8],
29
+ colWidths: [15, 50, 8],
30
30
  });
31
31
 
32
32
  // 4. 填充表格数据
@@ -34,7 +34,7 @@ function listAccounts() {
34
34
  const alias = path.basename(file, '.json');
35
35
  const address = getAddress(alias);
36
36
  const isActive = alias === activeAlias ? '*' : '';
37
- console.log("alias: ", alias, "address: ", address, "isActive: ", isActive,'activeAlias',activeAlias )
37
+ //console.log("alias: ", alias, "address: ", address, "isActive: ", isActive,'activeAlias',activeAlias )
38
38
  table.push([alias, address, isActive]);
39
39
  });
40
40
 
@@ -21,7 +21,7 @@ function getActiveKeyPath() {
21
21
  const config = execCommand('solana config get keypair');
22
22
  // 从输出中提取路径(例如:"Keypair Path: /home/user/.config/solana/keys/alice.json")
23
23
  const match = config.match(/Key Path: (.*)/);
24
- console.log("config:",config,"config match :",match)
24
+ //console.log("config:",config,"config match :",match)
25
25
  return match ? match[1] : null;
26
26
  }
27
27