2-2. Hardhat 환경 구축

동동주·2025년 9월 21일

hardhat.config.ts & tsconfig.json

Hardhat Document - Using TypeScript
Hardhat Document - Configuration

  • 기본 작성된 내용
import type { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox-viem";

const config: HardhatUserConfig = {
  solidity: "0.8.28",
};

export default config;
  • Configuration 문서 속 내용 (공식 사이트 그거)
module.exports = {
  defaultNetwork: "sepolia", // 여기도 hardhat으로 변경
  networks: {
    hardhat: {
    },
    sepolia: { 
    // 여기서 sepolia 부분 안써서 지워줌
      url: "https://sepolia.infura.io/v3/<key>",
      accounts: [privateKey1, privateKey2, ...]
    }
  },
  solidity: {
    version: "0.8.28",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  },
  paths: {
    sources: "./contracts",
    tests: "./test",
    cache: "./cache",
    artifacts: "./artifacts"
  },
  mocha: {
    timeout: 40000
  }
}

tsconfig.json
hardhat.config.ts
등등..
이 필요하다고 하는데
이전 설정(이전 글 참고)으로 인해 일단 파일+폴더는 다 있음.

toolbox

Hardhat Document - hardhat-toolbox
Hardhat Document - project-setup
이전에 viem 설정으로 인해 toolbox-viem 버전인데
선생님은 그냥 toolbox라서 안전하게 지우고 다시 깔았다

npm uninstall @nomicfoundation/hardhat-toolbox-viem //삭제
npm install --save-dev @nomicfoundation/hardhat-toolbox //설치

contracts & test

Hardhat Document - Quick start

  • Compiling your contracts
  • #Testing your contracts
    viem버전으로 다운받아놔서 test파일 사이트에서 복붙해야 함..
npx hardhat test                                                  ─╯
Downloading compiler 0.8.28
Compiled 1 Solidity file successfully (evm target: paris).


  Lock
    Deployment
      ✔ Should set the right unlockTime (328ms)
      ✔ Should set the right owner (50ms)
      ✔ Should receive and store the funds to lock
      ✔ Should fail if the unlockTime is not in the future (94ms)
    Withdrawals
      Validations
        ✔ Should revert with the right error if called too soon
        ✔ Should revert with the right error if called from another account
        ✔ Shouldn't fail if the unlockTime has arrived and the owner calls it (44ms)
      Events
        ✔ Should emit an event on withdrawals
      Transfers
        ✔ Should transfer the funds to the owner (116ms)

환경 구축
요런 형태였다

profile
배운 내용 정리&기록, 스크랩

0개의 댓글