npm package: @fliidotdev/blinks-cli
Description: CLI for Blinks SDK
Latest version: 0.1.3

# @fliidotdev/blinks-cli

Command-line interface for creating, managing, and deploying Solana Blinks. Build blockchain interactions from your terminal with powerful scaffolding and deployment tools.

## Installation

### Global Installation (Recommended)

```bash
npm install -g @fliidotdev/blinks-cli
# or
yarn global add @fliidotdev/blinks-cli
# or
pnpm add -g @fliidotdev/blinks-cli
```

### Local Installation

```bash
npm install --save-dev @fliidotdev/blinks-cli
# or
yarn add -D @fliidotdev/blinks-cli
# or
pnpm add -D @fliidotdev/blinks-cli
```

## Quick Start

```bash
# Create a new Blink project
blinks init my-blink-app

# Navigate to project
cd my-blink-app

# Start development server
blinks dev

# Deploy to mainnet
blinks deploy --network mainnet
```

## Commands

### `blinks init [project-name]`

Initialize a new Blinks project with boilerplate code and configuration.

```bash
blinks init my-project

# With options
blinks init my-project --template react --typescript --git
```

**Options:**
- `--template, -t` - Project template (`react` | `vue` | `vanilla` | `next`)
- `--typescript, --ts` - Use TypeScript (default: true)
- `--git` - Initialize git repository
- `--install, -i` - Install dependencies automatically
- `--pm` - Package manager (`npm` | `yarn` | `pnpm`)

### `blinks create [type]`

Create new Blink components and actions.

```bash
# Create a new action
blinks create action transfer-sol

# Create a new component
blinks create component payment-button

# Create a new hook
blinks create hook use-balance
```

**Types:**
- `action` - Create a new Blink action
- `component` - Create a React component
- `hook` - Create a custom React hook
- `contract` - Create a Solana program template

### `blinks dev`

Start the development server with hot reload.

```bash
blinks dev

# Custom port
blinks dev --port 4000

# With network
blinks dev --network devnet
```

**Options:**
- `--port, -p` - Port number (default: 3000)
- `--host, -h` - Host address (default: localhost)
- `--network, -n` - Solana network (`mainnet` | `devnet` | `testnet`)
- `--open, -o` - Open browser automatically

### `blinks build`

Build the project for production.

```bash
blinks build

# With optimization
blinks build --optimize

# Custom output directory
blinks build --out dist
```

**Options:**
- `--out, -o` - Output directory (default: build)
- `--optimize` - Enable optimization
- `--analyze` - Analyze bundle size
- `--sourcemap` - Generate source maps

### `blinks deploy`

Deploy Blinks to Solana network.

```bash
# Deploy to devnet
blinks deploy --network devnet

# Deploy to mainnet with custom RPC
blinks deploy --network mainnet --rpc https://api.mainnet-beta.solana.com

# Deploy specific Blink
blinks deploy payment-blink --network mainnet
```

**Options:**
- `--network, -n` - Target network (required)
- `--rpc, -r` - Custom RPC endpoint
- `--keypair, -k` - Path to keypair file
- `--program-id` - Program ID to deploy to
- `--dry-run` - Simulate deployment without executing

### `blinks test`

Run tests for your Blinks.

```bash
# Run all tests
blinks test

# Run specific test
blinks test payment.test.ts

# With coverage
blinks test --coverage

# Watch mode
blinks test --watch
```

**Options:**
- `--coverage, -c` - Generate coverage report
- `--watch, -w` - Run in watch mode
- `--bail` - Stop on first test failure
- `--verbose, -v` - Verbose output

### `blinks validate`

Validate Blink configurations and actions.

```bash
# Validate all Blinks
blinks validate

# Validate specific Blink
blinks validate payment-blink

# Validate with network check
blinks validate --network devnet
```

**Options:**
- `--network, -n` - Network to validate against
- `--strict` - Strict validation mode
- `--fix` - Auto-fix issues where possible

### `blinks list`

List all Blinks in the current project.

```bash
# List all Blinks
blinks list

# List with details
blinks list --detailed

# Filter by type
blinks list --type action
```

**Options:**
- `--detailed, -d` - Show detailed information
- `--type, -t` - Filter by type
- `--json` - Output as JSON

### `blinks wallet`

Manage wallet operations.

```bash
# Generate new wallet
blinks wallet generate

# Show wallet info
blinks wallet info

# Get balance
blinks wallet balance --network devnet

# Request airdrop (devnet only)
blinks wallet airdrop 2 --network devnet
```

**Subcommands:**
- `generate` - Generate new wallet keypair
- `info` - Display wallet information
- `balance` - Check wallet balance
- `airdrop` - Request SOL airdrop (devnet/testnet)

### `blinks config`

Manage CLI configuration.

```bash
# Show current config
blinks config

# Set default network
blinks config set network mainnet

# Set custom RPC
blinks config set rpc https://api.mainnet-beta.solana.com

# Get specific value
blinks config get network
```

**Subcommands:**
- `set [key] [value]` - Set configuration value
- `get [key]` - Get configuration value
- `reset` - Reset to default configuration
- `list` - List all configuration options

## Configuration

### Project Configuration

Create `blinks.config.js` in your project root:

```javascript
module.exports = {
  // Network configuration
  network: 'devnet',
  rpc: 'https://api.devnet.solana.com',
  
  // Build configuration
  build: {
    outDir: 'dist',
    sourcemap: true,
    minify: true
  },
  
  // Development server
  dev: {
    port: 3000,
    host: 'localhost',
    open: true
  },
  
  // Blink defaults
  defaults: {
    commitment: 'confirmed',
    preflightCommitment: 'processed'
  },
  
  // Custom paths
  paths: {
    actions: './src/actions',
    components: './src/components',
    contracts: './src/contracts'
  }
};
```

### TypeScript Configuration

For TypeScript projects, use `blinks.config.ts`:

```typescript
import { defineConfig } from '@fliidotdev/blinks-cli';

export default defineConfig({
  network: 'mainnet',
  rpc: process.env.SOLANA_RPC_URL,
  build: {
    target: 'es2020',
    lib: ['esnext', 'dom']
  }
});
```

### Environment Variables

Create `.env` file for environment-specific configuration:

```bash
# Network
SOLANA_NETWORK=devnet
SOLANA_RPC_URL=https://api.devnet.solana.com

# Wallet
WALLET_PRIVATE_KEY=your_private_key_here

# API Keys
HELIUS_API_KEY=your_helius_key
QUICKNODE_API_KEY=your_quicknode_key

# Development
DEV_PORT=3000
DEV_HOST=localhost
```

## Templates

### React Template

```bash
blinks init my-app --template react

# Includes:
# - React 18 with TypeScript
# - Solana wallet adapter
# - Pre-built components
# - Example actions
```

### Next.js Template

```bash
blinks init my-app --template next

# Includes:
# - Next.js 14 with App Router
# - Server-side rendering
# - API routes for Blinks
# - Optimized for production
```

### Vue Template

```bash
blinks init my-app --template vue

# Includes:
# - Vue 3 with Composition API
# - TypeScript support
# - Pinia for state management
# - Vue Router
```

### Vanilla Template

```bash
blinks init my-app --template vanilla

# Includes:
# - Pure JavaScript/TypeScript
# - No framework dependencies
# - Minimal bundle size
# - Web Components
```

## Programmatic API

Use the CLI programmatically in your Node.js applications:

```javascript
const { CLI } = require('@fliidotdev/blinks-cli');

const cli = new CLI();

// Initialize project
await cli.init('my-project', {
  template: 'react',
  typescript: true
});

// Create action
await cli.create('action', 'transfer', {
  template: 'transfer'
});

// Deploy
await cli.deploy({
  network: 'mainnet',
  rpc: 'https://api.mainnet-beta.solana.com'
});
```

## Plugins

Extend CLI functionality with plugins:

```javascript
// blinks.config.js
module.exports = {
  plugins: [
    '@fliidotdev/blinks-plugin-analytics',
    '@fliidotdev/blinks-plugin-monitoring',
    ['@fliidotdev/blinks-plugin-custom', {
      option1: 'value1'
    }]
  ]
};
```

## CI/CD Integration

### GitHub Actions

```yaml
name: Deploy Blinks

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      
      - name: Setup Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '18'
          
      - name: Install dependencies
        run: npm install
        
      - name: Install Blinks CLI
        run: npm install -g @fliidotdev/blinks-cli
        
      - name: Build
        run: blinks build --optimize
        
      - name: Deploy
        run: blinks deploy --network mainnet
        env:
          WALLET_PRIVATE_KEY: ${{ secrets.WALLET_PRIVATE_KEY }}
```

### Vercel Deployment

```json
{
  "buildCommand": "blinks build",
  "outputDirectory": "dist",
  "installCommand": "npm install && npm install -g @fliidotdev/blinks-cli"
}
```

## Troubleshooting

### Common Issues

1. **Command not found**
   ```bash
   # Reinstall globally
   npm install -g @fliidotdev/blinks-cli
   
   # Or use npx
   npx @fliidotdev/blinks-cli init
   ```

2. **Network connection issues**
   ```bash
   # Use custom RPC
   blinks deploy --rpc https://your-rpc-endpoint.com
   ```

3. **Transaction failures**
   ```bash
   # Increase commitment level
   blinks deploy --commitment finalized
   ```

4. **Build errors**
   ```bash
   # Clear cache
   blinks clean
   blinks build --no-cache
   ```

### Debug Mode

Enable debug output for troubleshooting:

```bash
# Enable debug mode
DEBUG=blinks:* blinks deploy

# Verbose logging
blinks deploy --verbose

# Dry run
blinks deploy --dry-run
```

## Best Practices

1. **Use environment variables** for sensitive data
2. **Test on devnet** before mainnet deployment
3. **Version control** your blinks.config.js
4. **Implement proper error handling** in custom actions
5. **Use TypeScript** for better type safety
6. **Regular backups** of wallet keypairs
7. **Monitor gas usage** and optimize transactions

## License

MIT © [fliidotdev](https://github.com/fliidotdev)

## Contributing

We welcome contributions! Please see our [Contributing Guide](https://github.com/fliidotdev/blinks-sdk/blob/main/CONTRIBUTING.md).

## Support

- [Documentation](https://docs.flii.dev/cli)
- [GitHub Issues](https://github.com/fliidotdev/blinks-sdk/issues)
- [Discord Community](https://discord.gg/fliidotdev)
- [Video Tutorials](https://youtube.com/@fliidotdev)