> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orbitflare.com/llms.txt
> Use this file to discover all available pages before exploring further.

# getVersion

> 返回节点的当前版本

## 参数

无

## 响应

<ResponseField name="result" type="object">
  包含以下内容的对象：

  <ResponseField name="solana-core" type="string">
    Solana 核心软件版本
  </ResponseField>

  <ResponseField name="feature-set" type="number" optional>
    功能集版本
  </ResponseField>
</ResponseField>

## 代码示例

### 基本请求

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getVersion"
}'
```

### 使用 web3.js

```typescript theme={null}
import { Connection } from '@solana/web3.js';

const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');

// Get version
const version = await connection.getVersion();
console.log('Node version:', version);

// Get version with analysis
async function getVersionWithAnalysis() {
  const version = await connection.getVersion();
  
  return {
    version,
    analysis: {
      timestamp: Date.now(),
      isLatest: await checkLatestVersion(version['solana-core'])
    }
  };
}

async function checkLatestVersion(currentVersion: string): Promise<boolean> {
  // Implementation to check if current version is latest
  // This would typically involve calling an external API
  return true;
}
```

## 注意事项

1. 返回节点的当前版本
2. 版本包括 Solana 核心软件版本
3. 响应是即时的，因为它从当前状态读取
4. 版本可能会随节点更新而变化
5. 不同节点可能运行不同版本

## 最佳实践

1. 在适当时缓存结果以减少 RPC 负载
2. 监控版本变化
3. 考虑使用 WebSocket 订阅获取实时更新
4. 适当处理网络错误并重试
5. 跟踪版本兼容性

## 常见错误

| 错误码    | 消息               | 解决方案                  |
| ------ | ---------------- | --------------------- |
| -32601 | Method not found | 验证是否连接到 Solana RPC 节点 |

## 用例

1. **版本分析**
   ```typescript theme={null}
   interface VersionAnalysis {
     version: {
       core: string;
       featureSet?: number;
     };
     metrics: {
       timestamp: number;
       isLatest: boolean;
       isCompatible: boolean;
     };
   }

   class VersionAnalyzer {
     private readonly minCompatibleVersion = '1.8.0';
     
     async analyzeVersion(): Promise<VersionAnalysis> {
       const version = await connection.getVersion();
       
       return {
         version: {
           core: version['solana-core'],
           featureSet: version['feature-set']
         },
         metrics: {
           timestamp: Date.now(),
           isLatest: await this.checkLatestVersion(version['solana-core']),
           isCompatible: this.checkCompatibility(version['solana-core'])
         }
       };
     }
     
     private async checkLatestVersion(currentVersion: string): Promise<boolean> {
       // Implementation to check if current version is latest
       return true;
     }
     
     private checkCompatibility(currentVersion: string): boolean {
       const [currentMajor, currentMinor] = currentVersion.split('.').map(Number);
       const [minMajor, minMinor] = this.minCompatibleVersion.split('.').map(Number);
       
       return currentMajor > minMajor || 
              (currentMajor === minMajor && currentMinor >= minMinor);
     }
   }
   ```

2. **版本监控**
   ```typescript theme={null}
   interface VersionChange {
     changes: {
       previousVersion: string;
       currentVersion: string;
       type: 'upgrade' | 'downgrade';
     };
     metadata: {
       timestamp: number;
     };
   }

   class VersionMonitor {
     private previousVersion: string | null = null;
     
     async monitorVersion(): Promise<VersionChange | null> {
       const version = await connection.getVersion();
       const currentVersion = version['solana-core'];
       
       if (this.previousVersion !== null && this.previousVersion !== currentVersion) {
         const type = this.compareVersions(currentVersion, this.previousVersion) > 0 ? 'upgrade' : 'downgrade';
         
         this.previousVersion = currentVersion;
         
         return {
           changes: {
             previousVersion: this.previousVersion,
             currentVersion,
             type
           },
           metadata: {
             timestamp: Date.now()
           }
         };
       }
       
       this.previousVersion = currentVersion;
       return null;
     }
     
     private compareVersions(v1: string, v2: string): number {
       const [major1, minor1, patch1] = v1.split('.').map(Number);
       const [major2, minor2, patch2] = v2.split('.').map(Number);
       
       if (major1 !== major2) return major1 - major2;
       if (minor1 !== minor2) return minor1 - minor2;
       return patch1 - patch2;
     }
   }
   ```

3. **版本规划**
   ```typescript theme={null}
   interface VersionPlan {
     currentVersion: string;
     recommendations: Array<{
       type: 'upgrade' | 'downgrade' | 'maintain';
       reason: string;
     }>;
     metadata: {
       timestamp: number;
     };
   }

   class VersionPlanner {
     private readonly targetVersion = '1.9.0';
     private readonly minCompatibleVersion = '1.8.0';
     
     async planVersion(): Promise<VersionPlan> {
       const version = await connection.getVersion();
       const currentVersion = version['solana-core'];
       
       const recommendations: Array<{
         type: 'upgrade' | 'downgrade' | 'maintain';
         reason: string;
       }> = [];
       
       // Check for version compatibility
       if (!this.checkCompatibility(currentVersion)) {
         recommendations.push({
           type: 'upgrade',
           reason: `Current version (${currentVersion}) is not compatible with minimum version (${this.minCompatibleVersion})`
         });
       }
       
       // Check for target version
       if (this.compareVersions(currentVersion, this.targetVersion) < 0) {
         recommendations.push({
           type: 'upgrade',
           reason: `Current version (${currentVersion}) is below target version (${this.targetVersion})`
         });
       }
       
       return {
         currentVersion,
         recommendations,
         metadata: {
           timestamp: Date.now()
         }
       };
     }
     
     private checkCompatibility(currentVersion: string): boolean {
       const [currentMajor, currentMinor] = currentVersion.split('.').map(Number);
       const [minMajor, minMinor] = this.minCompatibleVersion.split('.').map(Number);
       
       return currentMajor > minMajor || 
              (currentMajor === minMajor && currentMinor >= minMinor);
     }
     
     private compareVersions(v1: string, v2: string): number {
       const [major1, minor1, patch1] = v1.split('.').map(Number);
       const [major2, minor2, patch2] = v2.split('.').map(Number);
       
       if (major1 !== major2) return major1 - major2;
       if (minor1 !== minor2) return minor1 - minor2;
       return patch1 - patch2;
     }
   }
   ```
