Open hariprasad9899 opened 1 year ago
same issue here. anyone solved this?
I found the issue. It seems there are some weird behaviors from ethers 6.x.x. Do the following fixed my problem:
Try changing the version of ethers to ^5.7.2 in the package.json file. You can do this by running two commands: first, remove the current version of ethers using
yarn remove ethers
,
and second, add version 5.7.2 using
yarn add ethers@5.7.2
Try changing the version of ethers to ^5.7.2 in the package.json file. You can do this by running two commands: first, remove the current version of ethers using
yarn remove ethers
, and second, add version 5.7.2 usingyarn add ethers@5.7.2
Thanks! That solves
I got this issue too... to resolve this issue, change your ethers version form version 6 to somewhere in 5.
run this: yarn
yarn remove ethers
yarn add --dev ethers@5.7.2
npm
npm uninstall ethers
npm install -D ethers@5.7.2
I think version 6 got new ways to implement this. staying in version 5 might be better for learning this
This was actually driving me crazy. Thank you all!
@peibo0318 thanks man ! it works!
ethers.js V6 has been released, so I'm providing a solution for ethers V6.
You need to update your hardhat according to the following link: https://github.com/NomicFoundation/hardhat/releases/tag/%40nomicfoundation%2Fhardhat-toolbox%403.0.0
Then modify the code to:
describe("FundMe", function () {
let fundMe
let deployer
let mockV3Aggregator
let MockV3AggregatorAddress
beforeEach(async () => {
deployer = (await getNamedAccounts()).deployer
deployer = await ethers.provider.getSigner(deployer)
const Deployments = await deployments.fixture(["all"])
const fundMeAddress = Deployments.FundMe.address
MockV3AggregatorAddress = Deployments.MockV3Aggregator.address
fundMe = await ethers.getContractAt("FundMe", fundMeAddress, deployer)
// mockV3Aggregator = await ethers.getContractAt(
// "MockV3Aggregator",
// MockV3AggregatorAddress,
// deployer
// )
})
describe("constructor", function () {
it("sets the aggregator addresses correctly", async () => {
const response = await fundMe.getPriceFeed()
console.log(response)
// mockV3AggregatorAddress = await mockV3Aggregator.getAddress()
assert.equal(response, MockV3AggregatorAddress)
})
})
})
I ended up writing an ethers-v6-compatible getContract
JavaScript function which I call in several places in this project. It returns the contract and also the signer.
Note: I've forgotten why I added the deploymentsFixtureTags section. Ignore it or remove it if you don't know why it's useful.
Below is the contents of my getContract.js
file, which I placed in a utils
directory.
Hopefully it's of use to someone.
const {
deployments,
ethers,
} = require("hardhat")
const getContract = async (contractName, deploymentsFixtureTags) => {
// for local testing re-use the same deployment
if (deploymentsFixtureTags) {
await deployments.fixture(deploymentsFixtureTags)
}
// console.log({contractName})
signer = await ethers.provider.getSigner()
// console.log({signer})
const deployment = await deployments.get(contractName)
// console.log({deployment})
const contract = await ethers.getContractAt(
contractName,
deployment.address,
signer
)
// console.log({fundMe})
return {signer, contract};
}
module.exports = {
getContract
}
Here's an example call site from the fund.js
script file. This particular call site only needs the contract
return value, and so ignores the signer
return value.
...
const {getContract} = require('../utils/getContract')
...
({contract: fundMe} = await getContract("FundMe"))
const transactionResponse = await fundMe.fund({
value: valueToSend,
})
...
I am trying to run test cases, following the tutorial. I also remove the async function from the describe. But still getting the error, when running the test case.
Also, I have deployed the contract in the local network and testnet. There wasn't any issues. Only when running test case, it is throwing error.
What might be the reason?