solidity-development by pluginagentmarketplace/custom-plugin-blockchain
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-blockchain --skill solidity-development掌握 Solidity 智能合约开发,包括设计模式、测试策略和生产环境最佳实践。
# 调用此技能进行 Solidity 开发
Skill("solidity-development", topic="patterns", solidity_version="0.8.24")
现代 Solidity 核心内容:
经过实战检验的模式:
全面的测试策略:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
安全的升级模式:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract SecureVault {
mapping(address => uint256) public balances;
error InsufficientBalance();
error TransferFailed();
function withdraw(uint256 amount) external {
// 1. 检查
if (balances[msg.sender] < amount) revert InsufficientBalance();
// 2. 效果
balances[msg.sender] -= amount;
// 3. 交互
(bool ok,) = msg.sender.call{value: amount}("");
if (!ok) revert TransferFailed();
}
}
contract TokenFactory {
event TokenCreated(address indexed token, address indexed owner);
function createToken(
string memory name,
string memory symbol
) external returns (address) {
Token token = new Token(name, symbol, msg.sender);
emit TokenCreated(address(token), msg.sender);
return address(token);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "forge-std/Test.sol";
contract VaultTest is Test {
Vault vault;
address alice = makeAddr("alice");
function setUp() public {
vault = new Vault();
vm.deal(alice, 10 ether);
}
function test_Deposit() public {
vm.prank(alice);
vault.deposit{value: 1 ether}();
assertEq(vault.balances(alice), 1 ether);
}
function testFuzz_Withdraw(uint256 amount) public {
amount = bound(amount, 0.01 ether, 10 ether);
vm.startPrank(alice);
vault.deposit{value: amount}();
vault.withdraw(amount);
vm.stopPrank();
assertEq(vault.balances(alice), 0);
}
function test_RevertWhen_InsufficientBalance() public {
vm.prank(alice);
vm.expectRevert(Vault.InsufficientBalance.selector);
vault.withdraw(1 ether);
}
}
| 模式 | 使用场景 | 复杂度 |
|---|---|---|
| CEI | 所有状态变更 | 低 |
| 工厂模式 | 多个实例 | 低 |
| 克隆模式 (1167) | 节省 Gas 的复制 | 中 |
| UUPS | 可升级 | 中 |
| 钻石代理 | 无限制大小 | 高 |
| 陷阱 | 问题 | 解决方案 |
|---|---|---|
| 栈过深 | >16 个变量 | 使用结构体或辅助函数 |
| 合约过大 | >24KB | 拆分为库 |
| 重入攻击 | 调用后状态变更 | 使用 CEI 模式 |
| 缺少访问控制 | 任何人都可以调用 | 添加修饰器 |
// 解决方案 1: 使用结构体
struct Params { uint256 a; uint256 b; uint256 c; }
// 解决方案 2: 块作用域
{ uint256 temp = x + y; }
// 解决方案 3: 内部函数
function _helper(uint256 a) internal { }
# 检查合约大小
forge build --sizes
解决方案:拆分为库,使用钻石代理模式。
# 开发工作流
forge init # 新建项目
forge build # 编译
forge test -vvv # 运行测试
forge coverage # 覆盖率报告
forge fmt # 格式化代码
forge snapshot # Gas 快照
03-solidity-expertethereum-development, smart-contract-security| 版本 | 日期 | 变更 |
|---|---|---|
| 2.0.0 | 2025-01 | 生产级 Foundry 集成和模式 |
| 1.0.0 | 2024-12 | 初始版本 |
每周安装量
130
代码仓库
GitHub 星标数
1
首次出现
2026年1月24日
安全审计
安装于
opencode105
codex98
gemini-cli93
github-copilot90
cursor79
claude-code78
Master Solidity smart contract development with design patterns, testing strategies, and production best practices.
# Invoke this skill for Solidity development
Skill("solidity-development", topic="patterns", solidity_version="0.8.24")
Modern Solidity essentials:
Battle-tested patterns:
Comprehensive test strategies:
Safe upgrade patterns:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract SecureVault {
mapping(address => uint256) public balances;
error InsufficientBalance();
error TransferFailed();
function withdraw(uint256 amount) external {
// 1. CHECKS
if (balances[msg.sender] < amount) revert InsufficientBalance();
// 2. EFFECTS
balances[msg.sender] -= amount;
// 3. INTERACTIONS
(bool ok,) = msg.sender.call{value: amount}("");
if (!ok) revert TransferFailed();
}
}
contract TokenFactory {
event TokenCreated(address indexed token, address indexed owner);
function createToken(
string memory name,
string memory symbol
) external returns (address) {
Token token = new Token(name, symbol, msg.sender);
emit TokenCreated(address(token), msg.sender);
return address(token);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "forge-std/Test.sol";
contract VaultTest is Test {
Vault vault;
address alice = makeAddr("alice");
function setUp() public {
vault = new Vault();
vm.deal(alice, 10 ether);
}
function test_Deposit() public {
vm.prank(alice);
vault.deposit{value: 1 ether}();
assertEq(vault.balances(alice), 1 ether);
}
function testFuzz_Withdraw(uint256 amount) public {
amount = bound(amount, 0.01 ether, 10 ether);
vm.startPrank(alice);
vault.deposit{value: amount}();
vault.withdraw(amount);
vm.stopPrank();
assertEq(vault.balances(alice), 0);
}
function test_RevertWhen_InsufficientBalance() public {
vm.prank(alice);
vm.expectRevert(Vault.InsufficientBalance.selector);
vault.withdraw(1 ether);
}
}
| Pattern | Use Case | Complexity |
|---|---|---|
| CEI | All state changes | Low |
| Factory | Multiple instances | Low |
| Clone (1167) | Gas-efficient copies | Medium |
| UUPS | Upgradeable | Medium |
| Diamond | Unlimited size | High |
| Pitfall | Issue | Solution |
|---|---|---|
| Stack too deep | >16 variables | Use structs or helpers |
| Contract too large | >24KB | Split into libraries |
| Reentrancy | State after call | Use CEI pattern |
| Missing access | Anyone can call | Add modifiers |
// Solution 1: Use struct
struct Params { uint256 a; uint256 b; uint256 c; }
// Solution 2: Block scoping
{ uint256 temp = x + y; }
// Solution 3: Internal function
function _helper(uint256 a) internal { }
# Check contract sizes
forge build --sizes
Solutions: Split into libraries, use Diamond pattern.
# Development workflow
forge init # New project
forge build # Compile
forge test -vvv # Run tests
forge coverage # Coverage report
forge fmt # Format code
forge snapshot # Gas snapshot
03-solidity-expertethereum-development, smart-contract-security| Version | Date | Changes |
|---|---|---|
| 2.0.0 | 2025-01 | Production-grade with Foundry, patterns |
| 1.0.0 | 2024-12 | Initial release |
Weekly Installs
130
Repository
GitHub Stars
1
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode105
codex98
gemini-cli93
github-copilot90
cursor79
claude-code78
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
115,300 周安装