/hardhat-craftform

Library for continuous integration of contract deployments

Primary LanguageTypeScriptMIT LicenseMIT

Hardhat-Craftform

For consistent smart constract deploy environment

Installation

npm install hardhat-craftform

Quick Start

  1. You should add some compilerOptions in tsconfig.json
    tsconfig.json
"compilerOptions": {
    "experimentalDecorators": true,
    "strictPropertyInitialization": false
}
  1. import hardhat-craftform at hardhat.config.ts
import "hardhat-craftform"
  1. then, import craft directory at the top of your scripts. (not in hardhat.config.ts)
import "../crafts"
  1. if you compile your solidity files, Contract Crafts will be auto-generated.
npx hardhat compile

4-1. Or you can manually generate crafts with:

npx hardhat craftform

Deploy Contract

import { craftform, ethers } from "hardhat"
import "../crafts"  // Here: you should import "crafts" directory

async function deployMyContract(){
    const [ owner ] = await ethers.getSigners();
    const myCraft = await craftform
        .contract("MyContract")
        .deploy(
            "MyContractAlias",   // if set null, alias will be set as contract name.(in this case, "MyContract")
            // deploy options, typescript fully supported.
            {
                from: owner.address,
                args: ["Hello, World!", 41]
            },
            
            // your custom config for contract
            // you should set config props at {root}/crafts/contract/../your-contract.config.ts
            {
                message: "Hello, World!",
                magicNumber: 41
            }
        )
}

Reuse deployed contract with saved configs

import { craftform, ethers } from "hardhat"
import "../crafts"  // Here: you should import "crafts" directory

async function deployMyContract(){
    const [ owner ] = await ethers.getSigners();
    const myCraft = await craftform..contract("MyContract").attach("MyContractAlias");
    console.log(myCraft.$config.message)        // Hello, World!
    console.log(myCraft.$config.magicNumber)    // 41
}

There are 3 ways to attach deployed contracts.

// default attach : alias will be set as contract name
const myCraft1 = await craftform.contract("MyContract").attach();

// aliased attach
const myCraft2 = await craftform.contract("MyContract").attach("MyContractAlias");

// address attach
const myCraft3 = await craftform.contract("MyContract").attach("0x0123456789abcdef...");