NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.34k stars 1.42k forks source link

Support ethers@^6.0.0 #3639

Closed Amxx closed 1 year ago

Amxx commented 1 year ago

Describe the feature

ethers.js is a dependency in the following packages:

With the recent release of version ^6.0.0, devs are going to want to migrate (in particular because 6.0.0 gets rid of BN in favor of native bigint).

I would love to see a version of the above plugins that are compatible with this new version of ethers.

Search terms

ethers v6

alcuadrado commented 1 year ago

Thanks for creating this issue, @Amxx! This is a top priority for us.

Agreed that everyone will want to migrate asap because of bigints.

Amxx commented 1 year ago

For the record, I tried to do the change locally, starting with "hardhat-ethers" (see this branch)

The main issue I ran into is ethers not exposing Signer like it used to (it used to be a class, now its an interface)

froggiedev commented 1 year ago

Is there any public timeline for ethers v6 moving out of beta?

Amxx commented 1 year ago

Is there any public timeline for ethers v6 moving out of beta?

Its been out of beta for 10 days: https://www.npmjs.com/package/ethers?activeTab=versions

alcuadrado commented 1 year ago

Small update: @fvictorio is working on it, he'll post more info about this in a few days. AFAIK the bulk of the work is in hardhat-ethers. We also need to make sure that some community plugins get updated, like typechain.

ZirionNeft commented 1 year ago

Hello! Any updates on this?

k06a commented 1 year ago

Related: https://github.com/NomicFoundation/hardhat/discussions/3650

RmbRT commented 1 year ago

any news on this? We are migrating to ethers v6, and the hardhat compile bindings no longer work.

fvictorio commented 1 year ago

We are working on it. We'll comment here when we have a beta version ready.

makinghappen commented 1 year ago

really important upgrade!

fvictorio commented 1 year ago

Hi folks, we released beta versions of our @nomiclabs/hardhat-ethers and @nomicfoundation/hardhat-chai-matchers plugins, with some initial support for ethers v6. We don't expect any significant API changes here (although it could happen if there's a good reason), so please give them a try if you can!

Since these are tagged versions, installing them is a bit different if you are using npm v7 or newer. Normally just installing them would be enough, but in this case you'll have to do this:

npm i --legacy-peer-deps @nomiclabs/hardhat-ethers@beta @nomicfoundation/hardhat-chai-matchers@beta "ethers@^6.2.0"

If you are using yarn v1 or an older version of npm, then you need to install those same packages, but the --legacy-peer-deps option is not necessary.

Let me know if you have any feedback or questions!

ddnexus commented 1 year ago

Thank you!

However I still cannot run tests because of https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/747 and typechain related modules.

jim380 commented 1 year ago

@fvictorio the main hardhat package is in the process of being upgraded to support Ethers v6 too, correct?

fvictorio commented 1 year ago

No changes are needed in Hardhat core

jim380 commented 1 year ago

No changes are needed in Hardhat core

I'm getting errors with getSigners(), do you reckon I didn't update my dependencies correctly?

fvictorio commented 1 year ago

getSigners comes from hardhat-ethers

vasilevskykv commented 1 year ago

It seems to me that hardhat-toolbox TS doesn't support version 6 of ethers. package-lock.json.txt The version of ethers.js is 5.7.0 Is there any way to uprgade toi version 6.3.0 for example?

fvictorio commented 1 year ago

Indeed, the toolbox doesn't support it yet. You can install it, and the relevant plugins, manually, but you have to use the --legacy-peer-deps flag, which will force you to install all the peer deps:

npm i --legacy-peer-deps @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers@beta @nomiclabs/hardhat-ethers@beta @nomiclabs/hardhat-etherscan chai ethers@6 hardhat-gas-reporter solidity-coverage @typechain/hardhat typechain @typechain/ethers-v6 @ethersproject/abi @ethersproject/providers

This won't be necessary after we release new (stable) versions of hardhat-ethers and hardhat-chai-matchers.

therealjmj commented 1 year ago

This is great! We're very excited for hardhat support of v6. 🎉 Is there an expected date when this could be production ready?

remon-nashid commented 1 year ago

Any hurdles with this endeavour that the community can help with? It's not clear what's missing here.

fvictorio commented 1 year ago

The best way to help right now is to try the beta and give feedback!

I expect we'll be able to release this as stable soon, and include it in the Hardhat toolbox.

syffs commented 1 year ago

Trying to use this beta with ethers@6 is causing some issues on my side: 1.

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/utils' is not defined by "exports" in C:\Users\admin\workspaces\project\node_modules\.pnpm\@openzeppelin+hardhat-upgrades@1.26.0_@nomiclabs+hardhat-ethers@3.0.0-beta.0_@nomiclabs+hardh_cvvjjw6slz3byvkaau2ckc634a\node_modules\ethers\package.json
    at new NodeError (node:internal/errors:372:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:472:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:753:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (C:\Users\admin\workspaces\project\node_modules\.pnpm\@cspotcode+source-map-support@0.8.1\node_modules\@cspotcode\source-map-support\source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Not sure why this pops up and how to fix this properly, but I can only work around it by editing the referenced package.json to add the following exports:

    "./lib/utils": {
      "import": "./lib.esm/utils/index.js",
      "default": "./lib.commonjs/utils/index.js"
    },
  1. typechain needs some adjustments:
    • adding proper typechain target pnpm add -D @typechain/ethers-v6
    • setting typechain target in hardhat.config.ts
      typechain: {
      target: "ethers-v6",
      },

any help appreciated!

fvictorio commented 1 year ago

@syffs that's weird. Do you have some easy way to reproduce that? Also, can you try doing the same thing but with npm instead of pnpm?

fvictorio commented 1 year ago

Hi everyone, we just published stable versions of hardhat-ethers and hardhat-chai-matchers that support ethers v6.

As explained in the release notes, Typechain's Hardhat plugin still doesn't work with this new version, which in turn means that we can't release a new version of our Toolbox. This means that, if you want to use this in a new project, you'll need to manually install the plugins you need. If you have an existing project that you want to migrate to ethers v6 and you use our Toolbox, you'll have to wait until it's ready.

I'm going to keep this issue open until we get Typechain and the Toolbox working with ethers v6.

borislav-itskov commented 1 year ago

Big step forward, though, congratulations and thank you for your hardwork. One question We're currently on ethers 6 and we're using hardhat for a local blockchain but running the tests with ethers6 instead of hardhat-ethers. It goes like this:

run npx hardhat node in a separate tab
run test with npx hardhat test but on the localhost network (not hardhat) and using ethers6 config

I'm wondering if I replace ethers6 with hardhat-ethers and replace all ethers6 functions with those from hardhat-ethers whether I'll be able to use the hardhat network instead of localhost for the tests. I'll give it a try at some point but nevertheless, I though it would still be good to have an answer here at this point. Once again, thank you

fvictorio commented 1 year ago

@borislav-itskov you should be able to do that, yes. I don't know the details of your setup, but I guess you are doing something like this (assuming typescript here):

import { ethers } from "ethers"

// ...

const provider = new ethers.JsonRpcProvider()
// stuff

If that's the case, you should install the plugin, require it in your config, and do something like:

import { ethers } from "hardhat"

// ...

const provider = ethers.provider;
// stuff

There are also things that should be easier with the hardhat-ethers plugin (like deploying contracts from your project), but that depends a lot on the details of your project.

k06a commented 1 year ago

Hi everyone, we just published stable versions of hardhat-ethers and hardhat-chai-matchers that support ethers v6.

@fvictorio are you gonna push new versions to NPM? :)

fvictorio commented 1 year ago

They are pushed in npm :confused: Were you not able to install them?

k06a commented 1 year ago

@fvictorio I see only 2.2.3: https://www.npmjs.com/package/@nomiclabs/hardhat-ethers

fvictorio commented 1 year ago

We renamed that plguin, it's under the @nomicfoundation org now: https://www.npmjs.com/package/@nomicfoundation/hardhat-ethers

fvictorio commented 1 year ago

Hi folks, we just released the new version of the Toolbox that uses ethers v6. Check the release notes to learn more.

I'm going to close this issue now. If you have a problem with the new toolbox, or the new hardhat-ethers or hardhat-chai-matchers plugin, please open a new issue.

sherpya commented 1 year ago

ethers v6.5.1 still has a problem with ts-node ERR_PACKAGE_PATH_NOT_EXPORTED, show I open a bug there or they will crucify me?

fvictorio commented 1 year ago

@sherpya ethers@6.5.1 works for me in a typescript hardhat project (which uses ts-node under the hood).

sherpya commented 1 year ago

@sherpya ethers@6.5.1 works for me in a typescript hardhat project (which uses ts-node under the hood).

maybe different version of ts-node (I'm using ts-node) or node (I'm using v18.16.0)

fvictorio commented 1 year ago

If you can make a minimal reproducible example, open an issue and I'll take a look.

sherpya commented 1 year ago

If you can make a minimal reproducible example, open an issue and I'll take a look.

I'm still migrating my project, I need a bit of time

sherpya commented 1 year ago

If you can make a minimal reproducible example, open an issue and I'll take a look.

I'm still migrating my project, I need a bit of time

nevermind, I had something wrong in the config, now it works, thanks

TrejGun commented 1 year ago

Trying to use this beta with ethers@6 is causing some issues on my side: 1.

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/utils' is not defined by "exports" in C:\Users\admin\workspaces\project\node_modules\.pnpm\@openzeppelin+hardhat-upgrades@1.26.0_@nomiclabs+hardhat-ethers@3.0.0-beta.0_@nomiclabs+hardh_cvvjjw6slz3byvkaau2ckc634a\node_modules\ethers\package.json
    at new NodeError (node:internal/errors:372:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:472:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:753:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (C:\Users\admin\workspaces\project\node_modules\.pnpm\@cspotcode+source-map-support@0.8.1\node_modules\@cspotcode\source-map-support\source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Not sure why this pops up and how to fix this properly, but I can only work around it by editing the referenced package.json to add the following exports:

    "./lib/utils": {
      "import": "./lib.esm/utils/index.js",
      "default": "./lib.commonjs/utils/index.js"
    },
  1. typechain needs some adjustments:

    • adding proper typechain target pnpm add -D @typechain/ethers-v6
    • setting typechain target in hardhat.config.ts
  typechain: {
    target: "ethers-v6",
  },

any help appreciated!

looks like this is related to OZ upgradeable contracts

sherpya commented 1 year ago

throw away this, I'm not sure how but it was causing problems

typechain: { target: "ethers-v6", },

TrejGun commented 1 year ago

@sherpya nope

https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/805

sherpya commented 1 year ago

@sherpya nope

OpenZeppelin/openzeppelin-upgrades#805

it's very strange, looks like randomly pops up, I've removed that entry and deleted node_modules, that fixed it for me

TrejGun commented 1 year ago

do you have

import "@openzeppelin/hardhat-upgrades";

in hardhat.config.ts ?

sherpya commented 1 year ago

do you have

import "@openzeppelin/hardhat-upgrades";

in hardhat.config.ts ?

no, but for me it was another package causing it

DaveAppleton commented 1 year ago

do you have

import "@openzeppelin/hardhat-upgrades";

in hardhat.config.ts ?

Trying to install OZ-hardhat-upgrades gives the following

~/Documents/akombalabs/CCIP ᐅ npm install --save-dev @openzeppelin/hardhat-upgrades@latest                 
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: hardhat-project@undefined
npm ERR! Found: ethers@5.7.2
npm ERR! node_modules/ethers
npm ERR!   dev ethers@"^5.7.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer ethers@"^6.1.0" from @nomicfoundation/hardhat-ethers@3.0.4
npm ERR! node_modules/@nomicfoundation/hardhat-ethers
npm ERR!   peer @nomicfoundation/hardhat-ethers@"^3.0.0" from @openzeppelin/hardhat-upgrades@2.1.1
npm ERR!   node_modules/@openzeppelin/hardhat-upgrades
npm ERR!     dev @openzeppelin/hardhat-upgrades@"2.1.1" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
alcuadrado commented 1 year ago

Hey @DaveAppleton, thanks for sharing, but can you report it to open zeppelin instead?

frangio commented 1 year ago

@openzeppelin/hardhat-upgrades works with Ethers v6 since 2.0.0.

@DaveAppleton It looks like you're trying to install the latest version of that plugin while you haven't yet updated your ethers and hardhat-ethers dependencies.

raghuzbyte commented 1 year ago

chai matches are failing with ethers v6 on testnet (mumbai), but it works on hardhat local network. i see an error "receipt should not be null" in expect ().to.emit() call

TrejGun commented 1 year ago

you probably have to use tx.wait()