Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrading to toolbox v3 #4

Merged
merged 3 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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=
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
pragma solidity 0.8.19;

contract Greeter {
string private greeting;
Expand Down
31 changes: 11 additions & 20 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,23 +16,22 @@ 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")
.addParam("account", "The account's address")
.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");
});


Expand All @@ -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
}
},
Expand All @@ -71,7 +62,7 @@ module.exports = {
currency: "USD",
},
solidity: {
version: "0.8.16",
version: "0.8.19",
settings: {
optimizer: {
enabled: true,
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
7 changes: 3 additions & 4 deletions scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 2 additions & 5 deletions test/sample-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down