Skip to content

Commit

Permalink
Merge pull request PaulRBerg#159 from DenhamPreen/dp/refactor-to-hard…
Browse files Browse the repository at this point in the history
…hat-deploy

Refactor the deploy script to use hardhat deploy rather than a task
  • Loading branch information
PaulRBerg authored May 28, 2023
2 parents 4e1f459 + 1db1c84 commit 968b460
Show file tree
Hide file tree
Showing 10 changed files with 955 additions and 459 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ coverage
dist
node_modules
types
deployments

# files
*.env
Expand Down
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,25 @@ $ pnpm clean
Deploy the contracts to Hardhat Network:

```sh
$ pnpm deploy:contracts --greeting "Bonjour, le monde!"
$ pnpm deploy:contracts"
```
### Tasks
#### Deploy Greeter
Deploy a new instance of the Greeter contract via a task:
```sh
$ pnpm task:deployGreeter --network ganache --greeting "Bonjour, le monde!"
```
#### Set Greeting
Run the `setGreeting` task on the Ganache network:
```sh
$ pnpm task:setGreeting --network ganache --greeting "Bonjour, le monde!" --account 3
```
## Tips
Expand All @@ -162,6 +180,24 @@ If you use VSCode, you can get Solidity syntax highlighting with the
To view the coverage report generated by `pnpm coverage`, just click `Go Live` from the status bar to turn the server
on/off.
## Local development with Ganache
### Install Ganache
```sh
$ npm i -g ganache
```
### Run a Development Blockchain
```sh
$ ganache -s test
```
> The `-s test` passes a seed to the local chain and makes it deterministic
Make sure to set the mnemonic in your `.env` file to that of the instance running with Ganache.
## License
This project is licensed under MIT.
18 changes: 18 additions & 0 deletions deploy/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();
const { deploy } = hre.deployments;

const greeter = await deploy("Greeter", {
from: deployer,
args: ["Bonjour, le monde!"],
log: true,
});

console.log(`Greeter contract: `, greeter.address);
};
export default func;
func.id = "deploy_greeter"; // id required to prevent reexecution
func.tags = ["Greeter"];
14 changes: 13 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import "@nomicfoundation/hardhat-toolbox";
import { config as dotenvConfig } from "dotenv";
import "hardhat-deploy";
import type { HardhatUserConfig } from "hardhat/config";
import type { NetworkUserConfig } from "hardhat/types";
import { resolve } from "path";

import "./tasks/accounts";
import "./tasks/deploy";
import "./tasks/greet";
import "./tasks/taskDeploy";

const dotenvConfigPath: string = process.env.DOTENV_CONFIG_PATH || "./.env";
dotenvConfig({ path: resolve(__dirname, dotenvConfigPath) });
Expand Down Expand Up @@ -58,6 +60,9 @@ function getChainConfig(chain: keyof typeof chainIds): NetworkUserConfig {

const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
namedAccounts: {
deployer: 0,
},
etherscan: {
apiKey: {
arbitrumOne: process.env.ARBISCAN_API_KEY || "",
Expand All @@ -83,6 +88,13 @@ const config: HardhatUserConfig = {
},
chainId: chainIds.hardhat,
},
ganache: {
accounts: {
mnemonic,
},
chainId: chainIds.ganache,
url: "http://localhost:8545",
},
arbitrum: getChainConfig("arbitrum-mainnet"),
avalanche: getChainConfig("avalanche"),
bsc: getChainConfig("bsc"),
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"ethers": "^5.7.2",
"fs-extra": "^10.1.0",
"hardhat": "^2.12.2",
"hardhat-deploy": "^0.11.29",
"hardhat-gas-reporter": "^1.0.9",
"lodash": "^4.17.21",
"mocha": "^10.1.0",
Expand Down Expand Up @@ -69,13 +70,15 @@
"clean": "rimraf ./artifacts ./cache ./coverage ./types ./coverage.json && pnpm typechain",
"compile": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile",
"coverage": "hardhat coverage --solcoverjs ./.solcover.js --temp artifacts --testfiles \"test/**/*.ts\" && pnpm typechain",
"deploy:contracts": "hardhat deploy:Greeter",
"deploy:contracts": "hardhat deploy",
"lint": "pnpm lint:sol && pnpm lint:ts && pnpm prettier:check",
"lint:sol": "solhint --max-warnings 0 \"contracts/**/*.sol\"",
"lint:ts": "eslint --ignore-path ./.eslintignore --ext .js,.ts .",
"postinstall": "DOTENV_CONFIG_PATH=./.env.example pnpm typechain",
"prettier:check": "prettier --check \"**/*.{js,json,md,sol,ts,yml}\"",
"prettier:write": "prettier --write \"**/*.{js,json,md,sol,ts,yml}\"",
"task:deployGreeter": "hardhat task:deployGreeter",
"task:setGreeting": "hardhat task:setGreeting",
"test": "hardhat test",
"typechain": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat typechain"
}
Expand Down
Loading

0 comments on commit 968b460

Please sign in to comment.