360 Secure SkillHub
360 安全技能中心

Solidity LSP

核心功能涵盖Solidity合约编译、solhint静态检查、常见安全漏洞检测、气体优化建议及语法高亮等代码智能支持,适配.sol文件。适用于以太坊、Substrate、ClawChain等场景的智能合约开发,可通过命令行完成各类操作,需先安装solc、solhint等依赖,还可集成slither做进阶安全分析,助力提升合约安全性与开发效率。

bowen31337
bowen31337
热度 70.02
最近更新 2026-04-30 11:35:56
分类:开发依赖:代码执行应用场景:代码审查 / 调试排错 / DevOps

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add solidity-lsp
Metadata
name
solidity-lsp
description
Solidity language server providing smart contract development support including compilation, linting, security analysis, and code intelligence for .sol files. Use when working with Ethereum smart contracts, Substrate pallets, or any Solidity code that needs compilation, security checks, gas optimization, or code navigation. Essential for ClawChain pallet development.

Solidity LSP

Solidity language server integration providing comprehensive smart contract development support through solc (Solidity compiler) and solhint (linter).

Capabilities

  • Compilation: Compile Solidity smart contracts with solc
  • Linting: Static analysis with solhint for best practices and security
  • Security: Detect common vulnerabilities (reentrancy, overflow, etc.)
  • Gas optimization: Identify expensive operations
  • Code intelligence: Syntax highlighting, error detection
  • Supported extensions: .sol

Installation

Install Solidity compiler and linter:

# Solidity compiler
npm install -g solc

# Solidity linter
npm install -g solhint

Verify installation:

solcjs --version
solhint --version

Usage

Compile Solidity Contract

solcjs --bin --abi contract.sol

Compile with optimization:

solcjs --optimize --bin --abi contract.sol

Lint Contract

Run solhint on a file:

solhint contracts/MyContract.sol

Run on entire project:

solhint 'contracts/**/*.sol'

Security Analysis

solhint includes security rules by default. For advanced security analysis, consider:

# Install slither (requires Python)
pip3 install slither-analyzer

# Run security analysis
slither contracts/

Configuration

solhint Configuration

Create .solhint.json in project root:

{
  "extends": "solhint:recommended",
  "rules": {
    "compiler-version": ["error", "^0.8.0"],
    "func-visibility": ["warn", {"ignoreConstructors": true}],
    "max-line-length": ["warn", 120],
    "not-rely-on-time": "warn",
    "avoid-low-level-calls": "warn",
    "no-inline-assembly": "warn"
  }
}

Hardhat/Foundry Integration

For full development environments, see references/frameworks.md.

Integration Pattern

When developing smart contracts:

  1. Write: Edit Solidity code
  2. Lint: Run solhint to catch issues early
  3. Compile: Use solcjs to verify compilation
  4. Analyze: Run security tools before deployment
  5. Test: Write comprehensive unit tests

Common Issues

  • Compiler version mismatch: Specify pragma version in contract
  • Gas optimization: Use view/pure where possible
  • Security: Never use tx.origin for authentication
  • Best practices: Follow Checks-Effects-Interactions pattern

More Information