From 24d96ff178499d1d7461d02baa567282fbc670db Mon Sep 17 00:00:00 2001 From: Sam Wellander Date: Wed, 17 Jan 2024 11:39:15 -0800 Subject: [PATCH] Fix/ethers v6 migration in hardhat (#15) --- .../hardhat/deploy/00_deploy_your_contract.ts | 3 +- packages/hardhat/package.json | 2 +- packages/hardhat/scripts/listAccount.ts | 5 +- packages/hardhat/test/YourContract.ts | 2 +- yarn.lock | 48 ++++++++++++++++++- 5 files changed, 53 insertions(+), 7 deletions(-) diff --git a/packages/hardhat/deploy/00_deploy_your_contract.ts b/packages/hardhat/deploy/00_deploy_your_contract.ts index 7cb3c4d..7d5561d 100644 --- a/packages/hardhat/deploy/00_deploy_your_contract.ts +++ b/packages/hardhat/deploy/00_deploy_your_contract.ts @@ -1,5 +1,6 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; +// import { Contract } from "ethers"; /** * Deploys a contract named "deployYourContract" using the deployer account and @@ -31,7 +32,7 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn autoMine: true, }); - // const yourContract = await hre.ethers.getContract("YourContract", deployer); + // const batchRegistry = await hre.ethers.getContract("BatchRegistry", deployer); }; export default deployYourContract; diff --git a/packages/hardhat/package.json b/packages/hardhat/package.json index 0958d52..849a698 100644 --- a/packages/hardhat/package.json +++ b/packages/hardhat/package.json @@ -33,7 +33,7 @@ "eslint": "^8.26.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-prettier": "^4.2.1", - "ethers": "^5.7.1", + "ethers": "^6.10.0", "hardhat": "^2.19.4", "hardhat-deploy": "^0.11.45", "hardhat-deploy-ethers": "^0.4.1", diff --git a/packages/hardhat/scripts/listAccount.ts b/packages/hardhat/scripts/listAccount.ts index 0f95f72..ffc46d4 100644 --- a/packages/hardhat/scripts/listAccount.ts +++ b/packages/hardhat/scripts/listAccount.ts @@ -24,10 +24,11 @@ async function main() { try { const network = availableNetworks[networkName]; if (!("url" in network)) continue; - const provider = new ethers.providers.JsonRpcProvider(network.url); + const provider = new ethers.JsonRpcProvider(network.url); + await provider._detectNetwork(); const balance = await provider.getBalance(address); console.log("--", networkName, "-- 📡"); - console.log(" balance:", +ethers.utils.formatEther(balance)); + console.log(" balance:", +ethers.formatEther(balance)); console.log(" nonce:", +(await provider.getTransactionCount(address))); } catch (e) { console.log("Can't connect to network", networkName); diff --git a/packages/hardhat/test/YourContract.ts b/packages/hardhat/test/YourContract.ts index 67a6174..a44cf04 100644 --- a/packages/hardhat/test/YourContract.ts +++ b/packages/hardhat/test/YourContract.ts @@ -10,7 +10,7 @@ describe("YourContract", function () { const [owner] = await ethers.getSigners(); const yourContractFactory = await ethers.getContractFactory("YourContract"); yourContract = (await yourContractFactory.deploy(owner.address)) as YourContract; - await yourContract.deployed(); + await yourContract.waitForDeployment(); }); describe("Deployment", function () { diff --git a/yarn.lock b/yarn.lock index 4ee029c..5a9ba68 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1958,7 +1958,7 @@ __metadata: eslint: ^8.26.0 eslint-config-prettier: ^8.5.0 eslint-plugin-prettier: ^4.2.1 - ethers: ^5.7.1 + ethers: ^6.10.0 hardhat: ^2.19.4 hardhat-deploy: ^0.11.45 hardhat-deploy-ethers: ^0.4.1 @@ -2646,6 +2646,13 @@ __metadata: languageName: node linkType: hard +"@types/node@npm:18.15.13": + version: 18.15.13 + resolution: "@types/node@npm:18.15.13" + checksum: 79cc5a2b5f98e8973061a4260a781425efd39161a0e117a69cd089603964816c1a14025e1387b4590c8e82d05133b7b4154fa53a7dffb3877890a66145e76515 + languageName: node + linkType: hard + "@types/node@npm:^10.0.3": version: 10.17.60 resolution: "@types/node@npm:10.17.60" @@ -4047,6 +4054,13 @@ __metadata: languageName: node linkType: hard +"aes-js@npm:4.0.0-beta.5": + version: 4.0.0-beta.5 + resolution: "aes-js@npm:4.0.0-beta.5" + checksum: cc2ea969d77df939c32057f7e361b6530aa6cb93cb10617a17a45cd164e6d761002f031ff6330af3e67e58b1f0a3a8fd0b63a720afd591a653b02f649470e15b + languageName: node + linkType: hard + "aes-js@npm:^3.1.2": version: 3.1.2 resolution: "aes-js@npm:3.1.2" @@ -7065,6 +7079,21 @@ __metadata: languageName: node linkType: hard +"ethers@npm:^6.10.0": + version: 6.10.0 + resolution: "ethers@npm:6.10.0" + dependencies: + "@adraffy/ens-normalize": 1.10.0 + "@noble/curves": 1.2.0 + "@noble/hashes": 1.3.2 + "@types/node": 18.15.13 + aes-js: 4.0.0-beta.5 + tslib: 2.4.0 + ws: 8.5.0 + checksum: 6f0a834b9b9bb31eceda9ac0a841b1061d5e2eefb5d0b042013db1c5abf48fa993ec0a602ae4c64d9e259d495fc01c100cf61f17e928e09eb43f0c7860f2a317 + languageName: node + linkType: hard + "ethjs-unit@npm:0.1.6": version: 0.1.6 resolution: "ethjs-unit@npm:0.1.6" @@ -13312,7 +13341,7 @@ __metadata: languageName: node linkType: hard -"tslib@npm:^2.0.0, tslib@npm:^2.1.0, tslib@npm:^2.4.0": +"tslib@npm:2.4.0, tslib@npm:^2.0.0, tslib@npm:^2.1.0, tslib@npm:^2.4.0": version: 2.4.0 resolution: "tslib@npm:2.4.0" checksum: 8c4aa6a3c5a754bf76aefc38026134180c053b7bd2f81338cb5e5ebf96fefa0f417bff221592bf801077f5bf990562f6264fecbc42cd3309b33872cb6fc3b113 @@ -14217,6 +14246,21 @@ __metadata: languageName: node linkType: hard +"ws@npm:8.5.0": + version: 8.5.0 + resolution: "ws@npm:8.5.0" + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: ^5.0.2 + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + checksum: 76f2f90e40344bf18fd544194e7067812fb1372b2a37865678d8f12afe4b478ff2ebc0c7c0aff82cd5e6b66fc43d889eec0f1865c2365d8f7a66d92da7744a77 + languageName: node + linkType: hard + "ws@npm:^7.4.5, ws@npm:^7.4.6, ws@npm:^7.5.1": version: 7.5.9 resolution: "ws@npm:7.5.9"