1.2.0 • Published 10 months ago

smartca v1.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

smartca

smartca is a powerful NPM package that allows users to audit their smart contracts efficiently. With its user-friendly interface and robust features, smartca streamlines the smart contract auditing process.

Installation

Install the package using npm:

npm i smartca

Usage

Follow these steps to use smartca for auditing your smart contracts:

  1. Create an example.js file with the following code:

    import { SmartCA } from 'smartca';
    import dotenv from 'dotenv';
    import fs from 'fs';
    import path from 'path';
    
    // Load environment variables
    dotenv.config();
    
    async function analyzeMyContract(contractPath) {
        try {
            // Check if file path is provided
            if (!contractPath) {
                console.error('Please provide the path to your smart contract file');
                console.log('Usage: node example.js <path-to-contract>');
                process.exit(1);
            }
    
            // Read the contract file
            const contractCode = fs.readFileSync(contractPath, 'utf8');
            
            // Initialize SmartCA with your Hugging Face API key
            const analyzer = new SmartCA(process.env.HUGGINGFACE_API_KEY);
            
            // Analyze the contract
            const analysis = await analyzer.analyzeContract(contractCode);
            
            // Print results
            console.log(`\nAnalyzing contract: ${path.basename(contractPath)}\n`);
            console.log('Analysis Results:');
            console.log('Security Score:', analysis.securityScore);
            console.log('Code Quality Score:', analysis.codeQualityScore);
            console.log('Performance Score:', analysis.performanceScore);
            
            console.log('\nRecommendations:');
            analysis.recommendations.forEach((rec, index) => {
                console.log(`${index + 1}. ${rec}`);
            });
            
            console.log('\nMetrics:');
            console.log('Function Count:', analysis.metrics.functionCount);
            console.log('State Variables:', analysis.metrics.stateVariables);
            console.log('Complexity Score:', analysis.metrics.complexity);
        } catch (error) {
            if (error.code === 'ENOENT') {
                console.error('Error: Contract file not found');
            } else {
                console.error('Analysis failed:', error);
            }
        }
    }
    
    // Get the contract file path from command line arguments
    const contractPath = process.argv[2];
    
    // Run the analysis
    analyzeMyContract(contractPath);
  2. Run the following command in your terminal to audit your smart contract:

    node example.js path/to/your/contract.sol

Features

  • Comprehensive Audits: Analyze your smart contracts for potential vulnerabilities.
  • Detailed Reports: Get insights and recommendations to improve your smart contract security.
  • Ease of Use: Designed to be simple and effective for both beginners and professionals.

Configuration

Make sure you have a .env file in your project directory containing your Hugging Face API key:

HUGGINGFACE_API_KEY=your-api-key

License

This package is licensed under the MIT License.


Feel free to contribute or report any issues to help improve smartca!

1.2.0

10 months ago

1.1.0

10 months ago

1.0.0

10 months ago