solana-balance-cli 1.0.1
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/LICENSE +16 -0
- package/README.md +180 -0
- package/dist/index.js +39 -0
- package/dist/price.js +23 -0
- package/dist/solana.js +19 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# Solana Balance CLI
|
|
2
|
+
|
|
3
|
+
A simple command-line tool to check your Solana wallet balance in both SOL and USD.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ Fetch real-time Solana wallet balance
|
|
8
|
+
- ✅ Display balance in SOL
|
|
9
|
+
- ✅ Convert balance to USD using live price data from CoinGecko
|
|
10
|
+
- ✅ Clean, formatted output
|
|
11
|
+
- ✅ Error handling for invalid addresses
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
### Install from npm (Recommended)
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g solana-balance-cli
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Install locally
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install solana-balance-cli
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Development Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
git clone <repository-url>
|
|
31
|
+
cd solana-balance-cli
|
|
32
|
+
npm install
|
|
33
|
+
npm run build
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
### Global Installation
|
|
39
|
+
|
|
40
|
+
After installing globally, you can use the `sol-balance` command from anywhere:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
sol-balance <WALLET_ADDRESS>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Local Installation
|
|
47
|
+
|
|
48
|
+
If installed locally, use it with npx:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npx sol-balance <WALLET_ADDRESS>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Or add it to your package.json scripts:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"scripts": {
|
|
59
|
+
"check-balance": "sol-balance"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Example
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
sol-balance CuieVDEDtLo7FypA9SbLM9saXFdb1dsshEkyErMqkRQq
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Output
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
🔍 Fetching wallet balance...
|
|
74
|
+
|
|
75
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
76
|
+
📍 Wallet: CuieVDEDtLo7FypA9SbLM9saXFdb1dsshEkyErMqkRQq
|
|
77
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
78
|
+
💰 Balance: 0.0057 SOL
|
|
79
|
+
💵 SOL Price: $123.23 USD
|
|
80
|
+
💸 USD Value: $0.71 USD
|
|
81
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Global Installation (Optional)
|
|
85
|
+
|
|
86
|
+
To use the tool globally as `sol-balance`:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npm link
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Then you can run:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
sol-balance <WALLET_ADDRESS>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Technologies Used
|
|
99
|
+
|
|
100
|
+
- **TypeScript** - Type-safe development
|
|
101
|
+
- **@solana/web3.js** - Solana blockchain interaction
|
|
102
|
+
- **axios** - HTTP requests for price data
|
|
103
|
+
- **commander** - CLI framework
|
|
104
|
+
- **CoinGecko API** - Real-time SOL/USD price data
|
|
105
|
+
|
|
106
|
+
## Project Structure
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
solana-balance-cli/
|
|
110
|
+
├── src/
|
|
111
|
+
│ ├── index.ts # Main CLI entry point
|
|
112
|
+
│ ├── solana.ts # Solana balance fetching logic
|
|
113
|
+
│ └── price.ts # USD price fetching logic
|
|
114
|
+
├── dist/ # Compiled JavaScript output
|
|
115
|
+
├── package.json
|
|
116
|
+
├── tsconfig.json
|
|
117
|
+
└── README.md
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Error Handling
|
|
121
|
+
|
|
122
|
+
The tool handles various error scenarios:
|
|
123
|
+
- Invalid wallet addresses
|
|
124
|
+
- Network connection issues
|
|
125
|
+
- API failures
|
|
126
|
+
|
|
127
|
+
## Development
|
|
128
|
+
|
|
129
|
+
### Version Management
|
|
130
|
+
|
|
131
|
+
This project uses [Changesets](https://github.com/changesets/changesets) for version management and changelog generation.
|
|
132
|
+
|
|
133
|
+
#### Creating a Changeset
|
|
134
|
+
|
|
135
|
+
When you make changes that should be released:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
npm run changeset
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
This will prompt you to:
|
|
142
|
+
1. Select the type of change (major, minor, patch)
|
|
143
|
+
2. Write a summary of the changes
|
|
144
|
+
|
|
145
|
+
This creates a changeset file in `.changeset/` that describes your changes.
|
|
146
|
+
|
|
147
|
+
#### Versioning and Publishing
|
|
148
|
+
|
|
149
|
+
To create a new version and update the changelog:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
npm run version
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
This will:
|
|
156
|
+
- Read all changesets
|
|
157
|
+
- Update the version in `package.json`
|
|
158
|
+
- Generate/update `CHANGELOG.md`
|
|
159
|
+
- Remove used changeset files
|
|
160
|
+
|
|
161
|
+
To publish to npm:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
npm run release
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
This will:
|
|
168
|
+
- Build the project
|
|
169
|
+
- Publish to npm using changesets
|
|
170
|
+
|
|
171
|
+
Or you can publish manually after versioning:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
npm run version
|
|
175
|
+
npm publish
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
ISC
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const solana_1 = require("./solana");
|
|
6
|
+
const price_1 = require("./price");
|
|
7
|
+
const program = new commander_1.Command();
|
|
8
|
+
program
|
|
9
|
+
.name('sol-balance')
|
|
10
|
+
.description('Check Solana wallet balance in SOL and USD')
|
|
11
|
+
.version('1.0.0')
|
|
12
|
+
.argument('<wallet-address>', 'Solana wallet address to check')
|
|
13
|
+
.action(async (walletAddress) => {
|
|
14
|
+
try {
|
|
15
|
+
console.log('\n🔍 Fetching wallet balance...\n');
|
|
16
|
+
const [balance, price] = await Promise.all([
|
|
17
|
+
(0, solana_1.getSolanaBalance)(walletAddress),
|
|
18
|
+
(0, price_1.getSolanaPrice)()
|
|
19
|
+
]);
|
|
20
|
+
const usdValue = balance * price;
|
|
21
|
+
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
22
|
+
console.log(`📍 Wallet: ${walletAddress}`);
|
|
23
|
+
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
24
|
+
console.log(`💰 Balance: ${balance.toFixed(4)} SOL`);
|
|
25
|
+
console.log(`💵 SOL Price: $${price.toFixed(2)} USD`);
|
|
26
|
+
console.log(`💸 USD Value: $${usdValue.toFixed(2)} USD`);
|
|
27
|
+
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof Error) {
|
|
31
|
+
console.error(`\n❌ Error: ${error.message}\n`);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
console.error('\n❌ An unknown error occurred\n');
|
|
35
|
+
}
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
program.parse();
|
package/dist/price.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getSolanaPrice = getSolanaPrice;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
async function getSolanaPrice() {
|
|
9
|
+
try {
|
|
10
|
+
const response = await axios_1.default.get('https://api.coingecko.com/api/v3/simple/price?ids=solana&vs_currencies=usd');
|
|
11
|
+
const price = response.data.solana.usd;
|
|
12
|
+
if (typeof price !== 'number') {
|
|
13
|
+
throw new Error('Invalid price data received');
|
|
14
|
+
}
|
|
15
|
+
return price;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error instanceof Error) {
|
|
19
|
+
throw new Error(`Failed to fetch SOL price: ${error.message}`);
|
|
20
|
+
}
|
|
21
|
+
throw new Error('Failed to fetch SOL price: Unknown error');
|
|
22
|
+
}
|
|
23
|
+
}
|
package/dist/solana.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSolanaBalance = getSolanaBalance;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
async function getSolanaBalance(walletAddress) {
|
|
6
|
+
try {
|
|
7
|
+
const connection = new web3_js_1.Connection('https://api.mainnet-beta.solana.com', 'confirmed');
|
|
8
|
+
const publicKey = new web3_js_1.PublicKey(walletAddress);
|
|
9
|
+
const balanceInLamports = await connection.getBalance(publicKey);
|
|
10
|
+
const balanceInSol = balanceInLamports / web3_js_1.LAMPORTS_PER_SOL;
|
|
11
|
+
return balanceInSol;
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error instanceof Error) {
|
|
15
|
+
throw new Error(`Failed to fetch Solana balance: ${error.message}`);
|
|
16
|
+
}
|
|
17
|
+
throw new Error('Failed to fetch Solana balance: Unknown error');
|
|
18
|
+
}
|
|
19
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "solana-balance-cli",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "CLI tool to check Solana wallet balance in SOL and USD",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"sol-balance": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"start": "node dist/index.js",
|
|
12
|
+
"dev": "tsc && node dist/index.js",
|
|
13
|
+
"prepublishOnly": "npm run build",
|
|
14
|
+
"changeset": "changeset",
|
|
15
|
+
"version": "changeset version",
|
|
16
|
+
"release": "npm run build && changeset publish"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"keywords": [
|
|
24
|
+
"solana",
|
|
25
|
+
"wallet",
|
|
26
|
+
"balance",
|
|
27
|
+
"cli",
|
|
28
|
+
"cryptocurrency",
|
|
29
|
+
"blockchain",
|
|
30
|
+
"sol"
|
|
31
|
+
],
|
|
32
|
+
"author": "",
|
|
33
|
+
"license": "ISC",
|
|
34
|
+
"type": "commonjs",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=14.0.0"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": ""
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@solana/web3.js": "^1.98.4",
|
|
44
|
+
"axios": "^1.13.2",
|
|
45
|
+
"commander": "^14.0.2"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@changesets/cli": "^2.29.8",
|
|
49
|
+
"@types/node": "^25.0.3",
|
|
50
|
+
"typescript": "^5.9.3"
|
|
51
|
+
}
|
|
52
|
+
}
|