0

I have successfully compiled my contracts, but currently my "deploy" script is not working. When running hh compile or running the script on testnet, it successfully says "nothing to compile", but then it just completes with 0 errors. This makes me think that there is an error in my deploy script or hardhat.config file.

Here is my helper-hardhat-config.js code:

const { ethers } = require("hardhat")

const networkConfig = {
    default: {
        name: "hardhat",
    },
    31337: {
        name: "localhost",
    },
    421613: {
        name: "ARB_GOERLI",
    },
    42161: {
        name: "ARB_MAINNET",
    },
}

const developmentChains = ["hardhat", "localhost"]
const VERIFICATION_BLOCK_CONFIRMATIONS = 6

module.exports = {
    networkConfig,
    developmentChains,
    VERIFICATION_BLOCK_CONFIRMATIONS
}

Here is my hardhat.config.js file:

require("@nomiclabs/hardhat-waffle")
require("@nomiclabs/hardhat-etherscan")
require("hardhat-deploy")
require("solidity-coverage")
require("hardhat-gas-reporter")
require("hardhat-contract-sizer")
require("dotenv").config()

const ARB_GOERLI_RPC_URL = process.env.ARB_GOERLI_RPC_URL
const ARB_MAINNET_RPC_URL = process.env.ARB_MAINNET_RPC_URL
const PRIVATE_KEY = process.env.PRIVATE_KEY 

// API key
const ARBISCAN_API_KEY = process.env.ARBISCAN_API_KEY
const REPORT_GAS = process.env.REPORT_GAS || false

module.exports = {
    defaultNetwork: "hardhat",
    networks: {
        hardhat: {
            chainId: 31337,
        },
        localhost: {
            chainId: 31337,
        },
        ARB_GOERLI: {
            url: ARB_GOERLI_RPC_URL,
            accounts: PRIVATE_KEY !== undefined ? [PRIVATE_KEY] : [],
            saveDeployments: true,
            chainId: 421613,
        },
        ARB_MAINNET: {
            url: ARB_MAINNET_RPC_URL,
            accounts: PRIVATE_KEY !== undefined ? [PRIVATE_KEY] : [],
            saveDeployments: true,
            chainId: 42161,
        },
    },
    etherscan: {
        apiKey: {
            ARB_GOERLI: ARBISCAN_API_KEY,
            ARB_MAINNET: ARBISCAN_API_KEY,
        },
    },
    gasReporter: {
        enabled: REPORT_GAS,
        currency: "USD",
        outputFile: "gas-report.txt",
        noColors: true,
    },
    gasReporter: {
        enabled: REPORT_GAS,
        currency: "USD",
        outputFile: "gas-report.txt",
        noColors: true,
    },
    namedAccounts: {
        deployer: {
            default: 0, 
            42161: 0,
        },
        player: {
            default: 1,
        },
    },
    solidity: {
        compilers: [
            {
                version: "0.8.13",
                settings: {
                    optimizer: {
                        enabled: true,
                        runs: 200,
                        details: {
                            yul: true,
                        },
                    },
                    viaIR: false,
                },
            },
            {
                version: "^0.8.0",
                settings: {
                    optimizer: {
                        enabled: true,
                        runs: 200,
                        details: {
                            yul: true,
                        },
                    },
                    viaIR: false,
                },
            },
            {
                version: "^0.8.4",
                settings: {
                    optimizer: {
                        enabled: true,
                        runs: 200,
                        details: {
                            yul: true,
                        },
                    },
                    viaIR: false,
                },
            },
            {
                version: "^0.8.1",
                settings: {
                    optimizer: {
                        enabled: true,
                        runs: 200,
                        details: {
                            yul: true,
                        },
                    },
                    viaIR: false,
                },
            },
            {
                version: "^0.8.9",
                settings: {
                    optimizer: {
                        enabled: true,
                        runs: 200,
                        details: {
                            yul: true,
                        },
                    },
                    viaIR: false,
                },
            },
            {
                version: ">=0.7.0 <0.9.0",
                settings: {
                    optimizer: {
                        enabled: true,
                        runs: 200,
                        details: {
                            yul: true,
                        },
                    },
                    viaIR: false,
                },
            },
        ],
    },
    mocha: {
        timeout: 200000, // 200 seconds max for running tests
    },
}

Finally, here is the Deploy script. I have many contracts that I need to deploy, so I only have one here as an example called Governor:

const { network } = require("hardhat")
const {
    developmentChains,
    VERIFICATION_BLOCK_CONFIRMATIONS,
} = require("../helper-hardhat-config.js")
const { verify } = require("../utils/verify.js")

module.exports = async ({ getNamedAccounts, deployments }) => {
    const { deploy, log } = deployments
    const { deployer } = await getNamedAccounts()
    const waitBlockConfirmations = developmentChains.includes(network.name)
        ? 1
        : VERIFICATION_BLOCK_CONFIRMATIONS

    log("----------------------------------------------------")
    const arguments = []
    const Governor = await deploy("Governor", {
        from: deployer,
        args: arguments,
        log: true,
        waitConfirmations: waitBlockConfirmations,
    })

    // Verify the deployment
    if (!developmentChains.includes(network.name) && process.env.ARBI_SCAN_API_KEY) {
        log("Verifying...")
        await verify(Governor.address, arguments)
    }
    log("----------------------------------------------------")
}

module.exports.tags = ["all", "Governor"]

1 Answer 1

0

Hardhat only runs the compiler when a new contract is in the contracts folder or when a contract has been modified since the last compilation.

Otherwise, when you run any task (like hardhat deploy, hardhat node, hardhat test, and so on), the compiler won't run and you will read the message "nothing to compile".

You can see the results of the compilation in the artifacts folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.