wighawag / hardhat-deploy-ethers

MIT License
70 stars 25 forks source link

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

Closed fabianschu closed 1 year ago

fabianschu commented 3 years ago

I'm having a simple hardhat project. I'm using the instructions from this issue https://github.com/wighawag/hardhat-deploy-ethers/issues/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 commented 3 years ago

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 commented 3 years ago

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

fabianschu commented 3 years ago

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 commented 3 years ago

@fabianschu can you try with an alias to a specific version of hardhat-deploy-ethers ? like npm:hardhat-deploy-ethers@0.3.0-beta.10

fabianschu commented 3 years ago

@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: XXXXX@1.0.0
npm ERR! Found: @nomiclabs/hardhat-ethers@0.3.0-beta.10
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/hardhat-waffle@2.0.1
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/hardhat-ethers@0.3.0-beta.10
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/hardhat-waffle@2.0.1
npm WARN node_modules/@nomiclabs/hardhat-waffle
npm WARN   dev @nomiclabs/hardhat-waffle@"*" from the root project
fabianschu commented 3 years ago

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 commented 2 years ago

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 commented 2 years ago

+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 commented 2 years ago

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 commented 2 years ago

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

Best to ask hardhat team there : https://github.com/nomiclabs/hardhat/issues/1040 :)

aspiers commented 2 years ago

@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 commented 2 years ago

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

SantanuDK commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

I solved this problem using the solution suggested in this comment https://github.com/Tenderly/hardhat-tenderly/issues/51#issuecomment-1199129116

rube-de commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

wighawag commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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