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

'getContract' function does not exist when used with hardhat-waffle #12

Closed
fabianschu opened this issue Jun 30, 2021 · 22 comments
Closed

Comments

@fabianschu
Copy link

fabianschu commented Jun 30, 2021

I'm having a simple hardhat project. I'm using the instructions from this issue #1 to circumvent the error 'getContract' function does not exist on HardhatRuntimeEnvironment.ethers. My
package.json looks as follows and everything works fine:

{
  "name": "hardhat-ts",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "hardhat test"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "hardhat": "^2.1.2",
    "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
    "hardhat-deploy": "^0.7.0-beta.56",
    "ethers": "^5.4.0",
    "@openzeppelin/contracts": "^4.1.0",
    "@types/chai": "^4.2.19",
    "@types/mocha": "^8.2.2",
    "@types/node": "^15.12.5",
    "chai": "^4.3.4",
    "ts-node": "^10.0.0",
    "typescript": "^4.3.4"
  }
}

So, I want to use the hardhat-waffle plugin. I do npm i -D @nomiclabs/hardhat-ethers. As a result I cannot use getContract, because I get the error'getContract' function does not exist on HardhatRuntimeEnvironment.ethers again. My package.json looks now looks like this:

{
  "name": "hardhat-ts",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "hardhat test"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@nomiclabs/hardhat-waffle": "^2.0.1",
    "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
    "@openzeppelin/contracts": "^4.1.0",
    "@types/chai": "^4.2.19",
    "@types/mocha": "^8.2.2",
    "@types/node": "^15.12.5",
    "chai": "^4.3.4",
    "ethers": "^5.4.0",
    "hardhat": "^2.1.2",
    "hardhat-deploy": "^0.7.0-beta.56",
    "ts-node": "^10.0.0",
    "typescript": "^4.3.4"
  }
}

Any ideas how I can fix this?
cheers

@wighawag
Copy link
Owner

wighawag commented Jul 2, 2021

For that issue you currently need to install hardhat-deploy-ethers as alias.

See https://github.com/wighawag/hardhat-deploy-ethers#installation

I'm the future (waiting for some changes in hardhat itself) this will hopefully not be required anymore

@banshee
Copy link

banshee commented Jul 8, 2021

I created #13 because I'm not sure how to follow that installation advice. Seems like that breaks also.

@fabianschu
Copy link
Author

Sorry, the code that I had posted was not correct. In fact I had installed hardhat-deploy-ethers as alias. I updated the code for the second package.json. Still, the problem persists. @wighawag

@wighawag
Copy link
Owner

@fabianschu can you try with an alias to a specific version of hardhat-deploy-ethers ? like npm:[email protected]

@fabianschu
Copy link
Author

@wighawag I tried that. Here is my dependencies:

"devDependencies": {
    "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.10",
    "@nomiclabs/hardhat-waffle": "^2.0.1",
    "chai": "^4.3.4",
    "ethereum-waffle": "^3.4.0",
    "ethers": "^5.4.1",
    "hardhat": "^2.4.1",
    "hardhat-deploy": "^0.7.0-beta.46",
    "hardhat-gas-reporter": "^1.0.4",
    "solhint": "^3.3.3"
  },
  "dependencies": {
    "@openzeppelin/contracts": "^4.2.0",
    "eslint": "^7.30.0",
    "solidity-coverage": "^0.7.16"
  }

I first installed hardhat-deploy-ethers by adding this line "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.10", to the package.json, then npm i. Then I installed hardhat-waffle by running npm install -D @nomiclabs/hardhat-waffle. I got the folliwing error:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: @nomiclabs/[email protected]
npm ERR! node_modules/@nomiclabs/hardhat-ethers
npm ERR!   dev @nomiclabs/hardhat-ethers@"npm:hardhat-deploy-ethers@^0.3.0-beta.10" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @nomiclabs/hardhat-ethers@"^2.0.0" from @nomiclabs/[email protected]
npm ERR! node_modules/@nomiclabs/hardhat-waffle
npm ERR!   dev @nomiclabs/hardhat-waffle@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/XXXXX/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/XXXXXX/.npm/_logs/2021-07-21T08_19_51_758Z-debug.log

I force-installed hardhat-waffle npm install -D @nomiclabs/hardhat-waffle --force and now I have access to the getContract function and tests are still working. So, it seems to work, but it feels a bit shaky. Upon force-installing hardhat-waffle I got this message:

npm WARN using --force Recommended protections disabled.
npm WARN ERESOLVE overriding peer dependency
npm WARN Found: @nomiclabs/[email protected]
npm WARN node_modules/@nomiclabs/hardhat-ethers
npm WARN   dev @nomiclabs/hardhat-ethers@"npm:hardhat-deploy-ethers@^0.3.0-beta.10" from the root project
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer @nomiclabs/hardhat-ethers@"^2.0.0" from @nomiclabs/[email protected]
npm WARN node_modules/@nomiclabs/hardhat-waffle
npm WARN   dev @nomiclabs/hardhat-waffle@"*" from the root project

@fabianschu
Copy link
Author

Fun fact: with yarn, these dependencies can be installed without an error and both hardhat-deploy-ethers and hardhat-waffle seem to work.

  "devDependencies": {
    "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.10",
    "@nomiclabs/hardhat-waffle": "^2.0.1",
    "chai": "^4.3.4",
    "ethereum-waffle": "^3.4.0",
    "ethers": "^5.4.1",
    "hardhat": "^2.4.1",
    "hardhat-deploy": "^0.7.11",
    "hardhat-gas-reporter": "^1.0.4",
    "solhint": "^3.3.3"
  },
  "dependencies": {
    "@openzeppelin/contracts": "^4.2.0",
    "eslint": "^7.30.0",
    "solidity-coverage": "^0.7.16"
  }

@RickVM
Copy link

RickVM commented Aug 26, 2021

Ran into the same problem. Took me quite a while before I found this but @fabianschu's suggestion to use Yarn AND the specific version reference fixed it.

@jrfrantz
Copy link

jrfrantz commented Sep 8, 2021

+1 the suggestion of yarn + specific version (copypasted full line "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.10",) worked for me

@rube-de
Copy link

rube-de commented Oct 28, 2021

For that issue you currently need to install hardhat-deploy-ethers as alias.

See https://github.com/wighawag/hardhat-deploy-ethers#installation

I'm the future (waiting for some changes in hardhat itself) this will hopefully not be required anymore

do you have an idea/time horizon when that will happen?

@wighawag
Copy link
Owner

do you have an idea/time horizon when that will happen?

Best to ask hardhat team there : NomicFoundation/hardhat#1040 :)

@aspiers
Copy link

aspiers commented Mar 16, 2022

@jrfrantz commented on September 8, 2021 10:38 PM:

+1 the suggestion of yarn + specific version (copypasted full line "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.10",) worked for me

Does this work for anyone with the latest ^0.3.0-beta.13?

@aspiers
Copy link

aspiers commented Mar 16, 2022

I think I'm possibly seeing the same issue with hardhat-ethernal, which also hardcodes its dependency with @nomiclabs/hardhat-ethers.

jannikluhn added a commit to DAOgameDAO/daoplomacy that referenced this issue Mar 30, 2022
See wighawag/hardhat-deploy-ethers#12

Still doesn't work with `npm install`, but `yarn install` is fine.
@SantanuDK
Copy link

i think using npm running this command might help npm install -D @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers ethers it worked for me.

@samlaf
Copy link

samlaf commented Jul 5, 2022

Same problem with https://github.com/Tenderly/hardhat-tenderly which hardcodes @nomiclabs/hardhat-ethers . I will open an issue in their repo. How should they go about fixing this? How do they not hardcode a version of hardhat-ethers that gives us freedom to use hardhat-deploy-ethers instead?

@jvalenciag
Copy link

I solved this problem using the solution suggested in this comment Tenderly/hardhat-tenderly#51 (comment)

@rube-de
Copy link

rube-de commented Sep 19, 2022

I solved this problem using the solution suggested in this comment Tenderly/hardhat-tenderly#51 (comment)

first it didn't work for me. But I re-checked to have similar dependencies as in the scaffold-eth repo and now it solved it for me

@wighawag
Copy link
Owner

hardhat-deploy-ethers@next has been released
Please, try it out.

It is now an extension to hardhat-ethers so you need both

But note that that new version do not support external artifact if you were using them

@n00b21337
Copy link

can you help with this, where is this "hardhat-deploy-ethers@next" version?

@wighawag
Copy link
Owner

wighawag commented May 3, 2023

the latest is https://www.npmjs.com/package/hardhat-deploy-ethers/v/0.4.0-next.1

you can use the tag when installing

npm i -D hardhat-deploy-ethers@next

@n00b21337
Copy link

the latest is https://www.npmjs.com/package/hardhat-deploy-ethers/v/0.4.0-next.1

you can use the tag when installing

npm i -D hardhat-deploy-ethers@next

how come on GitHub there are no tags for those next releases?
https://github.com/wighawag/hardhat-deploy-ethers/tags

@wighawag
Copy link
Owner

wighawag commented May 3, 2023

how come on GitHub there are no tags for those next releases?
https://github.com/wighawag/hardhat-deploy-ethers/tags

I am just not very good at making sure they are tagged :)

@n00b21337
Copy link

I was searching there 2 months ago, then again today, couldn't find it and was thinking WTF am I missing :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests