0

I'm trying to create a fund function that allows users to fund their wallet after signing. I had my contract address & ABI stored in an external file and tried to export and import, but that didn't work. Please note: I'm a newbie. If what I'm saying doesn't make sense,here is a picture:

enter image description here

After connecting and funding my contract, this is what my code results in:

Dapp.js:35 Uncaught (in promise) ReferenceError: Cannot access 'contractAddress' before initialization
    at fundMe (Dapp.js:35:53)
    at HTMLButtonElement.<anonymous> (Dapp.js:13:5)
1
  • Consider providing the Dapp.js code directly into your question body as opposed to a screenshot, this will help us to help you.
    – Rohan Nero
    Commented Sep 25, 2023 at 21:56

1 Answer 1

0

Without seeing the rest of your Dapp.js code I can't be entirely sure of what the issue is, but based on what I can see, it seems like you are trying to declare a variable using the same name as an already existing variable.

const contractAddress = new ethers.contract(contractAddress, abi)

Instead of declaring the contract variable contractAddress, try renaming it:

const myContract = new ethers.contract(contractAddress, abi)

This way you aren't shadowing your imported variable with the same name.

2
  • 1
    Thanks alot, this was also what i did thanks for assisting me.
    – SABER
    Commented Sep 29, 2023 at 17:44
  • @SABER No problem glad to help! Make sure to mark the answer as accepted using the little green checkmark when you get a chance to show that your problem was solved
    – Rohan Nero
    Commented Sep 29, 2023 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.