PatrickAlphaC / hardhat-smartcontract-lottery-fcc

MIT License
117 stars 183 forks source link

Error: Getting no subscription Id from transaction Receipt #174

Closed rezowansifat closed 11 months ago

rezowansifat commented 11 months ago

I'm not getting any event properties from transactionReceipt at 01_deploy-raffle.js while running "npx hardhat deploy".

`if (chainId == 31337) {
    vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
    vrfCoordinatorV2Address = vrfCoordinatorV2Mock.getAddress()
    const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()
    const transactionReceipt = await transactionResponse.wait()

    subscriptionId = transactionReceipt.events[0].args.subId
    await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, FUND_AMOUNT)
} else {
    vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2"]
    subscriptionId = networkConfig[chainId]["subscriptionId"]
}`

Showing me this error 
Error: ERROR processing /deploy/01_deploy-raffle.js:
TypeError: Cannot read properties of undefined (reading '0')

My Repo: https://github.com/rezowansifat/Decentralized-Lottery.git
Rosa9120 commented 11 months ago

The problem is that you are using events instead of logs when you are reading the emitted events in 01-deploy-raffle.js and it is undefined. Try to change subscriptionId = transactionReceipt.events[0].args.subId to susbcriptionId = transactionReceipt.logs[0].args.subId

rezowansifat commented 11 months ago

Thank you, It was a success.