-
Beta Was this translation helpful? Give feedback.
Replies: 12 comments 21 replies
-
same here |
Beta Was this translation helpful? Give feedback.
-
Had same problem. Remove start and end quotes from abi.json. If that doesn't work, take the abi from the Raffle.json in the hardhat-smartcontract-lottery-fcc project, in the deployments folder. The idea is to come up with a solution to save the abi.json without quotes. EDIT: I'm following up on the previous solution, as I was in a hurry when I was writing it. The issue is that when we generate the abi.json in the update-front-end script as Patrick does in the tutorial, with JSON.stringify, it turns it into a string, which is not correctly recognized by our useWeb3Contract method. (he might change it later, don't know, I'm only at 17:46:00 :) ) If you take a look in the git repo at the 02-update-front-end.js file, the JSON.stringify is removed: |
Beta Was this translation helpful? Give feedback.
-
@Tosinkoa @alwayscommit were you able to fix this? i have similar issue |
Beta Was this translation helpful? Give feedback.
-
The error happens because the contract is deployed on a different chainId and your metamask wallet is trying to access the contract on a different chainId. If you've been following along with the course, then you should have these 2 local testnets:
So, check your hardhat-config and helper-hardhat-config files to check your chainId. If it is 31337, then set your metamask network to Hardhat-Localhost (or whatever you decided to name it) and if it is 1337, set your metamask to Localhost 8545. Bottom line, make sure that the chainId in your config files matches with the chainId of the network your metamask is on. In my case, I was trying to connect through the Rinkeby testnets without realizing, so neither 1337 nor 31337 in my config files worked, and you might be making the same mistake. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Hi! Here is my code; import { useWeb3Contract } from "react-moralis"
import {abi, contractAddresses} from "../constants"
import {useMoralis} from "react-moralis"
import { useEffect, useState } from "react"
import { ethers } from "ethers"
export default function LotteryEntrance(){
const {chainId: chainIdHex, isWeb3Enabled} = useMoralis()
const chainId = parseInt(chainIdHex)
console.log(chainId)
const raffleAddress = chainId in contractAddresses ? contractAddresses[chainId][0] : null
//console.log(raffleAddress)
// const {chainId: chainIdHex, isWeb3Enabled} = useMoralis()
// const chainId = parseInt(chainIdHex)
// console.log(chainId)
// const raffleAddress = chainId in contractAddresses ? contractAddresses[chainId][0] : null
//console.log(raffleAddress)
// const [entranceFee, setEntranceFee] = useState("0")
// const{runContractFunction: enterRaffle} = useWeb3Contract({
// abi: abi,
// contractAddress: raffleAddress,
// fucntionName: "enterRaffle",
// msgvalue: entranceFee,
// params: {},
// })
const{runContractFunction: getEntranceFee} = useWeb3Contract({
abi: abi,
contractAddress: raffleAddress,
fucntionName: "getEntranceFee",
params: {},
})
useEffect(() => {
if(isWeb3Enabled){
async function updateUI() {
const something = await getEntranceFee()
console.log(something)
}
updateUI()
}
}, [isWeb3Enabled])
// useEffect(() => {
// if (isWeb3Enabled){
// async function updateUI() {
// const something = await getEntranceFee()
// console.log(something)
// // const entranceFeeFromCall = (await getEntranceFee())//.toString()
// // console.log(entranceFeeFromCall)
// // // setEntranceFee(ethers.utils.formatUnits(entranceFeeFromCall), "ether")
// }
// updateUI()
// }
// }, [isWeb3Enabled])
//<div>Entrance Fee: {entranceFee} ETH</div>
return <div>
Hello from the other side
</div> |
Beta Was this translation helpful? Give feedback.
-
hi everyone ! |
Beta Was this translation helpful? Give feedback.
-
I could not fix this error for a long time and figured out that there was no need to It was adding a stringified version of json in my |
Beta Was this translation helpful? Give feedback.
-
Guys l'm facing a small challenge here, the line of code |
Beta Was this translation helpful? Give feedback.
-
For those who've tried everything here but still, nothing worked. I've faced the same problem, for me the issue was in the |
Beta Was this translation helpful? Give feedback.
-
just change the account you use to connect your wallet to "hardhat-localhost" is ok |
Beta Was this translation helpful? Give feedback.
-
My solution was to:
|
Beta Was this translation helpful? Give feedback.
The error happens because the contract is deployed on a different chainId and your metamask wallet is trying to access the contract on a different chainId. If you've been following along with the course, then you should have these 2 local testnets:
So, check your hardhat-config and helper-hardhat-config files to check your chainId. If it is 31337, then set your metamask network to Hardhat-Localhost (or whatever you decided to name it) and if it is 1337, set your metamask to Localhost 8545. Bottom line, make sure that the chainId in your config files matches with the chainId of the network your metamask is on. In my ca…