Lesson 8 - Error in hardhat Node but tx is happening in metamask #4783
-
Error:
index.js import { ethers } from "./ethers-5.6.esm.min.js"
import { abi, contractAddress } from "./constants.js"
let connectButton = document.getElementById("connect-Btn")
let fundButton = document.getElementById("fund-Btn")
connectButton.onclick = connect
fundButton.onclick = fund
async function connect() {
if (typeof window.ethereum !== "undefined") {
try {
await window.ethereum.request({ method: "eth_requestAccounts" })
} catch (error) {
console.log(error)
}
connectButton.innerText = "Connected!"
const accounts = await ethereum.request({ method: "eth_accounts" })
console.log(accounts)
} else {
connectButton.innerText = "Please Install Metamask"
}
}
//*fund
async function fund() {
const ethAmount = "0.1"
console.log(`Funding with ${ethAmount}....`)
if (typeof window.ethereum !== "undefined") {
//? What we need to send a transaction
//* provider/connection to blockchain
const provider = new ethers.providers.Web3Provider(window.ethereum)
//*signer/wallet/someone with some gas
const signer = provider.getSigner()
//* contract that we are interacting with
const contract = new ethers.Contract(contractAddress, abi, signer)
//* ABI & Address
const transactionResponse = await contract.fund({
value: ethers.utils.parseEther(ethAmount),
})
}
}
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@deepak2301 This is not passing the first condition of the fund function, either your price feed address is wrong or there might be an issue with the getConversionRate function. It would be better if you leave your fund me repository link. And for this |
Beta Was this translation helpful? Give feedback.
@deepak2301 This is not passing the first condition of the fund function, either your price feed address is wrong or there might be an issue with the getConversionRate function. It would be better if you leave your fund me repository link.
And for this
<unrecognized-selector>
you should first clean your artifacts folder by running this commandnpx hardhat clean
and then recompilenpx hardhat compile
and now add the newly generated abi to your frontend file. Do this whenever you update every single character inside your smart contracts to get the accurate abi for frontend.