-
Notifications
You must be signed in to change notification settings - Fork 0
/
solana-cli.ts
executable file
·62 lines (54 loc) · 1.82 KB
/
solana-cli.ts
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
import fs from 'fs'
import path from 'path'
// @ts-ignore
import inquirer from 'inquirer'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
// Questions to ask the user
const questions = [
{
type: 'input',
name: 'keyPath',
message: 'Please enter the path to your Solana key:',
validate: (input: string) => {
const filePath = path.resolve(input)
if (fs.existsSync(filePath)) {
return true
}
return 'The file path you entered does not exist. Please enter a valid path.'
},
},
{
type: 'input',
name: 'rpcUrl',
message: 'Please enter the Solana RPC URL:',
default: 'https://api.devnet.solana.com', // default can be changed as per requirement
validate: (input: string) => !!input && input.startsWith('http'),
},
]
// Prompt the user
inquirer
.prompt(questions)
.then((answers:any) => {
// Resolve the absolute path
const keyPath = path.resolve(answers.keyPath)
// Create a config object
const config = {
solanaKeyPath: keyPath,
solanaRPCUrl: answers.rpcUrl, // Added RPC URL to the config
}
// Convert the config object to a string
const configString = JSON.stringify(config, null, 2)
// Define the path to save the config
const configPath = path.resolve(__dirname, 'cli-config.json')
// Write the config string to a file
fs.writeFileSync(configPath, configString)
console.log(
'Solana key path and RPC URL have been set successfully in the CLI config.'
)
})
.catch((error: Error) => {
console.error('An error occurred:', error)
})