Lesson 7: Error when running script fund.js - fund is not a function #5830
-
I am running the following fund.js script: const { ethers, deployments } = require("hardhat"); async function main() {
} main() The contract is deployed to the localhost, however am getting the following error: Got contract FundMe at 0x71C95911E9a5D330f4D621842EC243EE1343292e This is my FundMe.sol: // SPDX-License-Identifier: MIT import "./PriceConverter.sol"; error NotOwner(); contract FundMe {
} |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Hey @avaradkar22 , use this in fund.js
and don't forget to use ethers version 5.7.2 |
Beta Was this translation helpful? Give feedback.
-
Hi @Naman1729 I changed my version of ethers and using ethers.getContract, however now I am getting the following error: TypeError: Cannot read properties of undefined (reading 'networks') Thanks for your help |
Beta Was this translation helpful? Give feedback.
-
Hi @avaradkar22 ! Since newer version of hardhat and ethersJs changes few syntax, a little change in your on const fundMe = await deployments.get("FundMe"); change this line with: { deployer } = await getNamedAccounts();
const fundMe = await getContract("FundMe", deployer); And on the top of the line import: const { getNamedAccounts, ethers } = require("hardhat"); on const transactionResponse = await fundMe.fund({
value: ethers.utils.parseEther("2"),
}); Change this line with: const transactionResponse = await fundMe.fund({
value: ethers.parseEther("2"),
}); Observe closely in newer version you have to do yarn hardhat run scripts/fund.js --network localhost and it will do the job 👍🏻 Note: remember you do have your |
Beta Was this translation helpful? Give feedback.
-
Was finally able to solve it by making the following change in the fund.js script: const fundMe = await ethers.getContract("FundMe", deployer); Also upgraded ethers to version 6.6.2 Thank you @Naman1729 and @pallab-nandi for your help |
Beta Was this translation helpful? Give feedback.
Was finally able to solve it by making the following change in the fund.js script:
const fundMe = await ethers.getContract("FundMe", deployer);
const fundMeAddress = await fundMe.getAddress();
console.log(
Got contract FundMe at ${fundMeAddress}
);Also upgraded ethers to version 6.6.2
Thank you @Naman1729 and @pallab-nandi for your help