hardhat-deploy Documentation

repository·main·Indexed 23 days ago

https://github.com/wighawag/hardhat-deploy

A Hardhat plugin for replicable, name-based EVM smart contract deployments. Built on the rocketh framework, it enables TypeScript-based deployment scripts, deterministic deployments, and declarative proxy or EIP-2535 Diamond deployments. Key features include a deployment dependency system, library linking, contract verification via Sourcify or Etherscan, and Hot Contract Replacement (HCR).

Tokens
760
Snippets
1
Records
4
Agent score
29%

What's inside hardhat-deploy

  1. Key features of hardhat-deploy

    main

    hardhat-deploy provides several advanced deployment capabilities:

    • Deterministic deployment: Ensure the same address across different networks.
    • Deployment dependency system: Only deploy what is strictly necessary.
    • Deployment retrying: Recover from interruptions by saving pending transactions.
    • Library linking: Link libraries at the time of deployment.
    • Chain configuration export: Export deployed contract addresses and ABIs (via @rocketh/export) for use in web applications.
    • Contract verification: Save metadata for full verification via Sourcify or Etherscan.
    • Test fixtures: Use deployments as optimized test fixtures via Hardhat helpers.
    • Hot Contract Replacement (HCR): Edit contracts and see changes live using proxy patterns.
  2. What is hardhat-deploy?

    main
    hardhat-deploy is a Hardhat plugin designed for replicable EVM smart contract deployments across multiple chains. It provides a mechanism to associate human-readable names with contract addresses, allowing deployment scripts and tests to remain decoupled from specific hex addresses. This enables you to use names instead of hardcoded accounts or addresses (e.g., avoiding accounts[0]).
  3. How hardhat-deploy and rocketh work together

    main

    hardhat-deploy v2 is built on top of rocketh, a framework-agnostic system that provides the core API for saving and loading deployments. While hardhat-deploy provides the Hardhat integration, the actual deployment logic is handled by modular @rocketh packages:

    • @rocketh/deploy: Provides the deploy function.
    • @rocketh/proxy: Enables declarative proxy deployments.
    • @rocketh/diamond: Enables declarative EIP-2535 Diamond deployments.
    • @rocketh/read-execute: Provides helpers for reading from and executing transactions on deployed contracts by name.
    • @rocketh/viem: Provides integration with the Viem client.
  4. Deploy a contract via proxy using deployScript

    main

    You can use deployScript to define deployment logic in plain TypeScript. The deployViaProxy function allows for declarative proxy deployment, which is useful for upgradeable contracts. You can pass namedAccounts to reference specific roles (like deployer or admin) instead of raw addresses.

    import { deployScript, artifacts } from "../rocketh/deploy.js";
    
    export default deployScript(
      async ({ deployViaProxy, namedAccounts }) => {
        const { deployer, admin } = namedAccounts;
    
        await deployViaProxy(
          "GreetingsRegistry",
          {
            account: deployer,
            artifact: artifacts.GreetingsRegistry,
            args: ["prefix:"],
          },
          {
            owner: admin,
          },
        );
      },
      { tags: ["GreetingsRegistry"] },
    );