Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting error : Uncaught TypeError: Cannot read properties of undefined (reading 'realEstate') at loadBlockchainData (App.js:31:1) #18

Open
Rackr7642 opened this issue May 28, 2023 · 4 comments

Comments

@Rackr7642
Copy link

Rackr7642 commented May 28, 2023

Full Error: p.js:31 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'realEstate')
at loadBlockchainData (App.js:31:1)
l

IDK why am I getting this error even though my syntax in right and I am doing exactly as shown in the video. Even after copying the code the error still doesn't resolve. Its fetching the data for the escrow one but not for the realEstate one.
Please help!

@AkinolaAkintunde
Copy link

Replace your loadBlockchaininData with this
' const loadBlockchainData = async () => {
try {
const provider = new ethers.providers.Web3Provider(window.ethereum);
setProvider(provider);

  const network = await provider.getNetwork();
  const chainId = network.chainId;

  const contractAddresses = config[chainId];
  if (!contractAddresses) {
    throw new Error(`No contract addresses found for chainId ${chainId}`);
  }

  const realEstate = new ethers.Contract(contractAddresses.realEstate.address, RealEstate, provider);
  const totalSupply = await realEstate.totalSupply();
  const homes = [];

  for (var i = 1; i <= totalSupply; i++) {
    const uri = await realEstate.tokenURI(i);
    const response = await fetch(uri);
    const metadata = await response.json();
    homes.push(metadata);
  }

  setHomes(homes)

  const escrow = new ethers.Contract(contractAddresses.escrow.address, Escrow, provider);
  setEscrow(escrow);

  window.ethereum.on('accountsChanged', async () => {
    const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
    const account = ethers.utils.getAddress(accounts[0])
    setAccount(account);
  });
} catch (error) {
  console.error("Error loading blockchain data:", error);
}

};'

@sandhu28
Copy link

sandhu28 commented Oct 4, 2023

You probably have not configured yout metamask properly. Watch the video at timestamp 1:32:00, and configure your hardhat, then follow the steps from running the command "npx hardhat node".

@elvisisvan
Copy link

You probably have not configured yout metamask properly. Watch the video at timestamp 1:32:00, and configure your hardhat, then follow the steps from running the command "npx hardhat node".

thank you, have you got it run and deploy smoothly?

@elvisisvan
Copy link

Replace your loadBlockchaininData with this ' const loadBlockchainData = async () => { try { const provider = new ethers.providers.Web3Provider(window.ethereum); setProvider(provider);

  const network = await provider.getNetwork();
  const chainId = network.chainId;

  const contractAddresses = config[chainId];
  if (!contractAddresses) {
    throw new Error(`No contract addresses found for chainId ${chainId}`);
  }

  const realEstate = new ethers.Contract(contractAddresses.realEstate.address, RealEstate, provider);
  const totalSupply = await realEstate.totalSupply();
  const homes = [];

  for (var i = 1; i <= totalSupply; i++) {
    const uri = await realEstate.tokenURI(i);
    const response = await fetch(uri);
    const metadata = await response.json();
    homes.push(metadata);
  }

  setHomes(homes)

  const escrow = new ethers.Contract(contractAddresses.escrow.address, Escrow, provider);
  setEscrow(escrow);

  window.ethereum.on('accountsChanged', async () => {
    const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
    const account = ethers.utils.getAddress(accounts[0])
    setAccount(account);
  });
} catch (error) {
  console.error("Error loading blockchain data:", error);
}

};'

basically wrap the entire loadBlockchainData property with a trycatch snippet, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants