-
Notifications
You must be signed in to change notification settings - Fork 183
Getting error TypeError: Cannot read properties of undefined (reading '0') in Lesson 9 #182
Comments
I have the same issue. Have you found a solution?? |
Well half of the problem get solved we can use this syntax to extract subscriptionId subscriptionId = transactionReceipt.logs[0].args.subId instead of this syntax subscriptionId = transactionReceipt.events[0].args.subId but still getting this error Error: Transaction reverted: function call to a non-contract account
at Raffle.performUpkeep (contracts/Raffle.sol:128)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at HardhatNode._mineBlockWithPendingTxs (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1840:23)
at HardhatNode.mineBlock (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:517:16)
at EthModule._sendTransactionAndReturnHash (node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:1532:18)
at HardhatNetworkProvider.request (node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:123:18)
at HardhatEthersSigner.sendTransaction (node_modules/@nomicfoundation/hardhat-ethers/src/signers.ts:125:18)
at send (node_modules/ethers/src.ts/contract/contract.ts:299:20)
|
@coderharsx1122! has provided a solution for this issue if you are working with ethers v5. (see If you happen to be stubborn like myself and want to migrate the project to ethers v6 with Typescript, I have found
const { deploy, log, get } = deployments
const vrfCoordinatorV2MockDeployment = await get('VRFCoordinatorV2Mock')
vrfCoordinatorV2Address = vrfCoordinatorV2MockDeployment.address
const vrfCoordinatorV2Mock = await ethers.getContractAt(
'VRFCoordinatorV2Mock',
vrfCoordinatorV2Address
) Here, we use the
const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()
const transactionReceipt = await transactionResponse.wait()
subscriptionId = transactionReceipt.events[0].args.subId Instead we are going to access the
I've since found out that the first index, [0], of the So let's go ahead a put in the last two lines of code as follows: subscriptionId = transactionReceipt!.logs[0].topics[1]
await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, VRF_SUB_FUND_AMOUNT) _A cheat code for this it to just set Here is the completed if (devChains.includes(network.name)) {
const vrfCoordinatorV2MockDeployment = await get('VRFCoordinatorV2Mock')
vrfCoordinatorV2Address = vrfCoordinatorV2MockDeployment.address
const vrfCoordinatorV2Mock = await ethers.getContractAt(
'VRFCoordinatorV2Mock',
vrfCoordinatorV2Address
)
const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()
const transactionReceipt = await transactionResponse.wait()
subscriptionId = transactionReceipt!.logs[0].topics[1]
await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, VRF_SUB_FUND_AMOUNT)
} else {
...
} Interested to hear anybody else's results utilizing this change. I'll keep this updated if this triggers any further issues down the line (as they usually do). e (as they usually do). Also, would love to connect with anyone else looking to work through this tutorial with the updated ethers library and TS as I'm sure there are plenty of opportunities to troubleshoot. |
Found a solution. I added the gasLane value to the hardhat chainId in the hardhat-helper-config.js then I hard coded the subscriptionId value to 1 |
Use this: |
Getting error in Lesson 9 Error: ERROR processing /root/hardhat-fcc/hardhat-smartcontract-lottery-fcc/deploy/01-deploy-raffle.js: TypeError: Cannot read properties of undefined (reading '0')
**Error occurring at line 23 **
Code at line 23 >
subscriptionId = transactionReceipt.events[0].args.subId
My 01-deploy-raffle.js file
The text was updated successfully, but these errors were encountered: