From e9fc847c42d1201a6a70249f321ecb1c596d219d Mon Sep 17 00:00:00 2001 From: Salman Dabbakuti Date: Sat, 30 Sep 2023 09:03:20 +0530 Subject: [PATCH] upgrading to toolbox v3 (#4) * updated: changes related to v3 toolbox * updated: dropping unsupported node v * Update README.md --- .env.example | 4 +--- .gitattributes | 2 -- .github/workflows/ci.yml | 12 +++++++----- README.md | 2 +- contracts/Greeter.sol | 2 +- hardhat.config.js | 31 +++++++++++-------------------- package.json | 12 ++++++------ scripts/deploy.js | 7 +++---- test/sample-test.js | 7 ++----- 9 files changed, 32 insertions(+), 47 deletions(-) delete mode 100644 .gitattributes diff --git a/.env.example b/.env.example index 8095965..0aa57ae 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,5 @@ # Be aware. dont commit this file or any of theses keys to your repo. -PRIV_KEY= -ETHEREUM_MAINNET_RPC_URL= -GOERLI_RPC_URL= +PRIVATE_KEY= POLYGON_MUMBAI_RPC_URL= POLYGON_MAINNET_RPC_URL= ETHERSCAN_API_KEY= \ No newline at end of file diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index dfe0770..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90ae2c4..be580b3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,27 +12,29 @@ on: jobs: e2e-test: - runs-on: ubuntu-latest strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - node-version: [14.x, 16.x, 18.x] + node-version: [16.x, 18.x, 20.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} on ${{ matrix.os }} uses: actions/setup-node@v3 # uses: borales/actions-yarn@v3.0.0 with: node-version: ${{ matrix.node-version }} - - name: "Install packages with latest npm" - run: npm i -g npm@latest && npm install + - name: "Install packages with npm" + run: npm install - name: "Copy .env.example to .env" run: cp .env.example .env - name: "Start hardhat node" run: npx hardhat node & sleep 3 + - name: "List accounts with balances" + run: npx hardhat accounts - name: "Check for solidity linter errors" run: npx hardhat check - name: "Compile contracts" diff --git a/README.md b/README.md index e8d452d..10c9554 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts with balances. -> Recommended to use Node.js v14+ and npm v7+. +> Recommended to use Node.js v16+ and npm v8+ > Rename `env.example` to `.env` and add your env specific keys. diff --git a/contracts/Greeter.sol b/contracts/Greeter.sol index 2c3871e..afbdc30 100644 --- a/contracts/Greeter.sol +++ b/contracts/Greeter.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: MIT -pragma solidity 0.8.16; +pragma solidity 0.8.19; contract Greeter { string private greeting; diff --git a/hardhat.config.js b/hardhat.config.js index 7c91589..9953c02 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -4,7 +4,7 @@ require("@nomiclabs/hardhat-solhint"); require('dotenv').config(); // defining accounts to reuse. -const accounts = process.env.PRIV_KEY ? [process.env.PRIV_KEY] : []; +const accounts = process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : []; // This is a sample Hardhat task. To learn how to create your own go to // https://hardhat.org/guides/create-task.html @@ -16,15 +16,14 @@ task("accounts", "Prints the list of accounts with balances", async () => { for (const account of accounts) { const balance = await provider.getBalance(account.address); - console.log(`${account.address} - ${ethers.utils.formatEther(balance)} ETH`); + console.log(`${account.address} - ${ethers.formatEther(balance)} ETH`); } }); task("deploy", "Deploys Contract", async () => { - const contractFactory = await ethers.getContractFactory("Greeter"); - const contract = await contractFactory.deploy("Hello, Hardhat!"); - await contract.deployed(); - console.log("contract deployed at:", contract.address); + const contract = await ethers.deployContract("Greeter", ["Hello, Hardhat!"]); + await contract.waitForDeployment(); + console.log("contract deployed at:", contract.target); }); task("balance", "Prints an account's balance") @@ -32,7 +31,7 @@ task("balance", "Prints an account's balance") .setAction(async ({ account }) => { const provider = await ethers.provider; const balance = await provider.getBalance(account); - console.log(hre.ethers.utils.formatEther(balance), "ETH"); + console.log(ethers.formatEther(balance), "ETH"); }); @@ -45,20 +44,12 @@ module.exports = { local: { url: "http://127.0.0.1:8545", }, - main: { - url: process.env.ETHEREUM_MAINNET_RPC_URL, - accounts: accounts - }, - goerli: { - url: process.env.GOERLI_RPC_URL, - accounts // private keys - }, - polygonMumbai: { - url: process.env.POLYGON_MUMBAI_RPC_URL, + mumbai: { + url: process.env.POLYGON_MUMBAI_RPC_URL || "https://rpc-mumbai.maticvigil.com", accounts }, - polygonMain: { - url: process.env.POLYGON_MAINNET_RPC_URL, + polygon: { + url: process.env.POLYGON_MAINNET_RPC_URL || "https://rpc-mainnet.maticvigil.com", accounts } }, @@ -71,7 +62,7 @@ module.exports = { currency: "USD", }, solidity: { - version: "0.8.16", + version: "0.8.19", settings: { optimizer: { enabled: true, diff --git a/package.json b/package.json index f5d3e77..4b7b810 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,10 @@ "author": "Salman Dabbakuti", "license": "ISC", "devDependencies": { - "@nomicfoundation/hardhat-chai-matchers": "^1.0.4", - "@nomicfoundation/hardhat-toolbox": "^2.0.0", - "@nomiclabs/hardhat-solhint": "^2.0.0", - "dotenv": "^16.0.3", - "hardhat": "^2.10.2" + "@nomicfoundation/hardhat-chai-matchers": "^2.0.2", + "@nomicfoundation/hardhat-toolbox": "^3.0.0", + "@nomiclabs/hardhat-solhint": "^3.0.1", + "dotenv": "^16.3.1", + "hardhat": "^2.17.4" } -} \ No newline at end of file +} diff --git a/scripts/deploy.js b/scripts/deploy.js index a447e26..c1ccace 100644 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -5,15 +5,14 @@ */ async function main() { - const contractFactory = await ethers.getContractFactory("Greeter"); - const contract = await contractFactory.deploy("Hello, Hardhat!"); - await contract.deployed(); + const contract = await ethers.deployContract("Greeter", ["Hello, Hardhat!"]); + await contract.waitForDeployment(); return contract; } main() .then(async (contract) => { - console.log("Contract deployed at:", contract.address); + console.log("Contract deployed at:", contract.target); // Write to contract const tx = await contract.setGreeting("Hello Ethereum Devs!"); await tx.wait(); diff --git a/test/sample-test.js b/test/sample-test.js index 49d8bc8..b3355db 100644 --- a/test/sample-test.js +++ b/test/sample-test.js @@ -13,12 +13,9 @@ describe("Contract Tests", function () { // `before` will run only once, useful for deploying the contract and use it on every test // It receives a callback, which can be async. before(async () => { - // Get the ContractFactory and Signers here. - const contractFactory = await ethers.getContractFactory("Greeter"); accounts = await ethers.getSigners(); - // Deploy the contract specifying the constructor arguments - greeterContract = await contractFactory.deploy("Hello, Hardhat!"); - await greeterContract.deployed(); + greeterContract = await ethers.deployContract("Greeter", ["Hello, Hardhat!"], { gasLimit: 1000000 }); + await greeterContract.waitForDeployment(); }); it("Should return the new greeting once it's changed", async function () {