PatrickAlphaC / hardhat-smartcontract-lottery-fcc

MIT License
118 stars 181 forks source link

TypeError: (0 , ethers_1.getAddress) is not a function #175

Open Sammycoderr opened 1 year ago

Sammycoderr commented 1 year ago

this seems to be the affected part, I hope I can get your views as soon as you see this. Thanks


        const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
        vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address
        const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()
        const transactionReceipt = await transactionResponse.wait(1)
        subscriptionId = transactionReceipt.events[0].args.subId

       }
Sammycoderr commented 1 year ago

here is the whole error message


An unexpected error occurred:

Error: ERROR processing /home/sammy/hh-fcc/hardhat-smartcontract-raffle-fcc/deploy/01-deploy-raffle.js:
TypeError: (0 , ethers_1.getAddress) is not a function
    at new HardhatEthersSigner (/home/sammy/hh-fcc/hardhat-smartcontract-raffle-fcc/node_modules/@nomicfoundation/hardhat-ethers/src/signers.ts:73:30)
    at Function.create (/home/sammy/hh-fcc/hardhat-smartcontract-raffle-fcc/node_modules/@nomicfoundation/hardhat-ethers/src/signers.ts:65:12)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at runNextTicks (node:internal/process/task_queues:64:3)
    at listOnTimeout (node:internal/timers:538:9)
    at processTimers (node:internal/timers:512:7)
    at getSigner (/home/sammy/hh-fcc/hardhat-smartcontract-raffle-fcc/node_modules/@nomicfoundation/hardhat-ethers/src/internal/helpers.ts:60:29)
    at async Promise.all (index 0)
    at getSigners (/home/sammy/hh-fcc/hardhat-smartcontract-raffle-fcc/node_modules/@nomicfoundation/hardhat-ethers/src/internal/helpers.ts:45:30)
    at getContractAt (/home/sammy/hh-fcc/hardhat-smartcontract-raffle-fcc/node_modules/@nomicfoundation/hardhat-ethers/src/internal/helpers.ts:327:21)
    at DeploymentsManager.executeDeployScripts (/home/sammy/hh-fcc/hardhat-smartcontract-raffle-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1229:19)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at runNextTicks (node:internal/process/task_queues:64:3)
    at listOnTimeout (node:internal/timers:538:9)
    at processTimers (node:internal/timers:512:7)
    at DeploymentsManager.runDeploy (/home/sammy/hh-fcc/hardhat-smartcontract-raffle-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1059:5)
    at SimpleTaskDefinition.action (/home/sammy/hh-fcc/hardhat-smartcontract-raffle-fcc/node_modules/hardhat-deploy/src/index.ts:438:5)
    at Environment._runTaskDefinition (/home/sammy/hh-fcc/hardhat-smartcontract-raffle-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:333:14)
    at Environment.run (/home/sammy/hh-fcc/hardhat-smartcontract-raffle-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:166:14)
    at SimpleTaskDefinition.action (/home/sammy/hh-fcc/hardhat-smartcontract-raffle-fcc/node_modules/hardhat-deploy/src/index.ts:584:32)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
rezowansifat commented 1 year ago

Try to change vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address to vrfCoordinatorV2Address = vrfCoordinatorV2Mock.runner.address

Sammycoderr commented 1 year ago

Try to change vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address to vrfCoordinatorV2Address = vrfCoordinatorV2Mock.runner.address

Thank you, so I did that with both .getAddress and .runner.address but still giving the exact error

CHANGLIFE commented 1 year ago

Here, I ran into the same problem. I've tried everything on the internet and it still doesn't work.

CHANGLIFE commented 1 year ago

Bro, have you solved it?

Sammycoderr commented 1 year ago

Bro, have you solved it?

oh yeah as a matter of fact I’ve solved it …if I remember correctly, basically our package.json has a bunch of version updates so somethings have been moved around. so downgrading to the versions he used during the tutorial would help. just copy them from the repository and run yarn.

I guess that was all I did but if it doesn’t work let’s know, happy coding

CHANGLIFE commented 1 year ago

Thanks, I did the same.It works

ilkinm03 commented 5 months ago

Installing this will solve issue

"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.13s"

And please make sure you're using ethers v5 module not v6.

Bethel-nz commented 4 months ago

still using ethersv6, i tried something else, but i cant seem to get the subId, sadly, im getting the address and all btw but not the subId which is missing in the txReceipt:

// create VRFV2 Subscription
    const deploymentAddress = (await deployments.get('VRFCoordinatorV2Mock'))
      .address;
    const vrfCoordinatorV2Mock = await ethers.getContractAt(
      'VRFCoordinatorV2Mock',
      deploymentAddress
    );
    vrfCoordinatorV2Address = await vrfCoordinatorV2Mock.getAddress();
    const txResponse = await vrfCoordinatorV2Mock.createSubscription();
    const txReceipt = await txResponse.wait();
    console.log(
      'reciept',
      await txResponse ,
      txReceipt?.toJSON()
    );
    //   subscriptionId = transactionReceipt?.logs[0]!.data;
    //   // Fund the subscription
    //   // Our mock makes it so we don't actually have to worry about sending fund
    //   await vrfCoordinatorV2Mock.fundSubscription(subscriptionId!, FUND_AMOUNT);
Bethel-nz commented 4 months ago

found a workaround:

  if (chainId == 31337) {
    // create VRFV2 Subscription
    const deploymentAddress = (await deployments.get('VRFCoordinatorV2Mock'))
      .address;
    const vrfCoordinatorV2Mock = await ethers.getContractAt(
      'VRFCoordinatorV2Mock',
      deploymentAddress
    );
    vrfCoordinatorV2Address = await vrfCoordinatorV2Mock.getAddress();
    const txResponse = await vrfCoordinatorV2Mock.createSubscription({
      from: deployer,
    });
    const txReceipt = await txResponse.wait();
    const logs = await txReceipt?.logs[0]!;

    if (logs && 'args' in logs) {
      subscriptionId = logs.args[0];
    }
    //   // Fund the subscription
    //   // Our mock makes it so we don't actually have to worry about sending fund
    await vrfCoordinatorV2Mock.fundSubscription(subscriptionId!, FUND_AMOUNT);
  } else {
    vrfCoordinatorV2Address =
      networkConfig[network.config.chainId!]['vrfCoordinatorV2'];
    subscriptionId = networkConfig[network.config.chainId!]['subscriptionId'];
  }