Socket
Book a DemoInstallSign in
Socket

test-hardhat-app

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

test-hardhat-app

A Hardhat 3 project

latest
npmnpm
Version
1.0.0
Version published
Weekly downloads
2
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

test-hardhat-app

A Hardhat 3 project

这是一个使用 Hardhat 3 创建的以太坊智能合约项目。

🚀 快速开始

安装依赖

npm install

编译合约

npm run compile

运行测试

# 运行所有测试
npm test

# 只运行 Solidity 测试
npm run test:solidity

# 只运行 Mocha 测试
npm run test:mocha

📝 项目结构

test-hardhat-app/
├── contracts/              # Solidity 智能合约
│   ├── Counter.sol        # 示例合约
│   └── examples/          # 更多示例合约
├── test/                  # 测试文件
│   ├── Counter.t.sol     # Solidity 测试
│   └── Counter.ts        # TypeScript 测试
├── scripts/               # 部署和交互脚本
│   ├── deploy.ts         # 部署脚本
│   ├── interact.ts       # 合约交互脚本
│   └── utils/            # 工具函数
├── ignition/             # Hardhat Ignition 部署模块
│   └── modules/
│       └── Counter.ts    # 声明式部署配置
├── hardhat.config.ts     # Hardhat 配置文件
└── README.md            # 项目文档

🔧 配置

环境变量

复制 .env.example.env 并填入你的配置:

cp .env.example .env

需要配置的变量:

  • SEPOLIA_RPC_URL - Sepolia 测试网 RPC URL
  • SEPOLIA_PRIVATE_KEY - 部署账户私钥
  • ETHERSCAN_API_KEY - Etherscan API Key(用于合约验证)

网络配置

项目已配置以下网络:

  • hardhatMainnet - 本地模拟主网
  • hardhatOp - 本地模拟 OP Stack
  • sepolia - Sepolia 测试网

📦 部署

使用脚本部署

# 部署到本地网络
npm run deploy

# 部署到 Sepolia 测试网
npm run deploy:sepolia

使用 Hardhat Ignition 部署

# 部署到本地网络
npm run ignition:deploy

# 部署到 Sepolia
npx hardhat ignition deploy ignition/modules/Counter.ts --network sepolia

🧪 测试

项目支持两种测试方式:

1. Solidity 测试(Foundry 风格)

// test/Counter.t.sol
pragma solidity ^0.8.28;

import "forge-std/Test.sol";
import "../contracts/Counter.sol";

contract CounterTest is Test {
    function test_Example() public {
        // 测试逻辑
    }
}

2. TypeScript 测试(Mocha + Ethers)

// test/Counter.ts
import { expect } from "chai";
import { network } from "hardhat";

const { ethers } = await network.connect();

describe("Counter", function () {
  it("Should work", async function () {
    const counter = await ethers.deployContract("Counter");
    // 测试逻辑
  });
});

📚 学习资源

  • Hardhat 3 文档
  • Hardhat 3 Beta 指南
  • Ethers.js 文档
  • OpenZeppelin 文档
  • Solidity 文档

🤝 贡献

欢迎提交 Issues 和 Pull Requests!

📄 许可证

MIT © 2025

FAQs

Package last updated on 14 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts