# hardhat_framework **Repository Path**: lightsever/hardhat_framework ## Basic Information - **Project Name**: hardhat_framework - **Description**: hardhat 开发智能合约的脚手架 - **Primary Language**: TypeScript - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 3 - **Created**: 2022-01-05 - **Last Updated**: 2023-06-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Basic Sample Hardhat Project hardhat 自己的脚手架很难用,改进一下。 这套框架曾用在一个30多个合约的巨型项目中 ## 环境准备 可以使用yarn 恢复 yarn install ## 日常开发 1.合约放在 contracts目录中,可以建立子目录。合约名称最好和文件名相同 2.合约发布需配置deployinfo.json,校验,测试均依赖此文件 3.test放置在test目录中,不要自己发布合约,全部用ContractInfo.getContract获取合约 可以在test init部分调用相应xdeploy 和xinit来进行合约准备。 这样一套test可以用于各种网络环境,直接发布的test不适合于生产环境。 4.init代码 在./utils/init/ 要自己添加和注册 添加之后就可以用 xinit 和 xcheck 进行合约的初始化与检查 5.合约中可以打log,用hardhat/console ,不会影响最终合约发布的hash 6.多用localhost node 节点test,更接近真实环境。 ## 命令用法 ### 基本 npx hardhat compile //编译sol合约 npx hardhat node //开启localhost节点 ### 测试 npx hardhat --network localhost test //执行测试 已经改为HardHat网络测试 npx hardhat --network localhost test ./test/greeter.ts 执行单个测试 ### 查询余额 npx hardhat --network bscTest xbalance deployer //检查一个namedaccount的余额 ### 发布合约 //原版发布,=xdeploy all , npx hardhat --network bscTest deploy //发布,信息写入deployresult_[network].json npx hardhat --network bscTest xdeploy all //发布所有合约。不初始化 npx hardhat --network bscTest xdeploy group [name]//发布一组合约 npx hardhat --network bscTest xdeploy one [name]//发布一个合约 ### 校验合约 //校验合约,自动调用发布 公开合约代码到环境 npx hardhat --network bscTest xverify all //校验所有合约 npx hardhat --network bscTest xverify group [name]//校验一组合约 npx hardhat --network bscTest xverify one [name]//校验一个合约 ### 初始化合约 //初始化合约,自动加载deployresult_[network].json npx hardhat --network bscTest xinit all npx hardhat --network bscTest xinit group [name] npx hardhat --network bscTest xinit one [name] ### 检查合约状态 //校验合约,自动加载deployresult_[network].json npx hardhat --network bscTest xcheck all npx hardhat --network bscTest xcheck group [name] npx hardhat --network bscTest xcheck one [name] ### 更新合约 //更新合约,自动加载deployresult_[network].json npx hardhat --network bscTest xupgrade [proxyname] [targetname|targetaddr] //例:npx hardhat --network localhost xupgrade XWorldDCLevelProxy XWorldDCLevel_0_2