3

My Code:

const ethers = require("hardhat")

const networkConfig = {
  4: {
    name: "goerli",
    vrfCoordinatorv2: "0x2Ca8E0C643bDe4C2E08ab1fA0da3401AdAD7734D",
    enterenceFee: ethers.utils.parseEther("1.0"),
    gasLane: "0x79d3d8832d904592c0bf9818b621522c988bb8b0c05cdc3b15aea1b6e8db0c15",
    subscriptionId: "0",
    callbackGasLimit: "500000",
    interval: "30",
  },
  31337: {
    name: "hardhat",
    entehenceFee: ethers.utils.parseEther("1.0"),
    gasLane: "0x79d3d8832d904592c0bf9818b621522c988bb8b0c05cdc3b15aea1b6e8db0c15",
  },
}

const developmentChains = ["hardhat", "localhost"]

module.exports = [networkConfig, developmentChains]

My Error:

Error: ERROR processing skip func of C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\deploy\00-deploy-mocks.js:
TypeError: Cannot read properties of undefined (reading 'parseEther')
    at Object.<anonymous> (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\helper-hardhat-config.js:7:32)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\deploy\00-deploy-mocks.js:5:31)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at DeploymentsManager.executeDeployScripts (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1100:15)
    at DeploymentsManager.runDeploy (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1052:16)
    at SimpleTaskDefinition.action (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat-deploy\src\index.ts:438:5)
    at Environment._runTaskDefinition (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat\src\internal\core\runtime-environment.ts:311:14)
    at Environment.run (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat\src\internal\core\runtime-environment.ts:159:14)
    at SimpleTaskDefinition.action (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat-deploy\src\index.ts:584:32)
    at Environment._runTaskDefinition (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat\src\internal\core\runtime-environment.ts:311:14)
    at Environment.run (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat\src\internal\core\runtime-environment.ts:159:14)
    at SimpleTaskDefinition.action (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat-deploy\src\index.ts:669:5)
    at Environment._runTaskDefinition (C:\Users\user\OneDrive\Desktop\BlockChain\hardhat-lottery\node_modules\hardhat\src\internal\core\runtime-environment.ts:311:14)

Can Someone tell me where I am incorrect? I am not able to figure it out..

6 Answers 6

7

Check out the first line of your code:

const ethers = require("hardhat")

You're importing Hardhat as ethers, an easy fix would be to do something like

const { ethers } = require("hardhat")

or just call it hardhat and use hardhat.ethers wherever you're using ethers right now.

2
  • Yes, thanks Ziyad
    – Yana Gupta
    Feb 11, 2023 at 21:39
  • 1
    Feel free to mark this as accepted so it doesn't show up as unanswered. Feb 11, 2023 at 21:48
8

function "parseEther" have been migrated from ethers.utils to ethers .

So when you want to use that in version 6, just use

  • ethers.parseEther("0.05")

or, you can downgrade your ethers version to 5. You can look up these docs.

  1. ethers 6 doc
  2. ethers 5 doc
0

function "parseEther" have been migrated from ethers.utils to ethers .

If you are using version 6 so then use ethers.parseEther("0.01") like this.

otherwise, Downgrade your ethers latest version to 5:

yarn add [email protected] or npm install [email protected]

1
  • Please provide an explanation on why this may fix the problem. Jul 13, 2023 at 7:53
0

you should add below import statement this should work

const { parseEther } = require("ethers/lib/utils");

const sendValue = parseEther("1")

0

now you know most of the function are change so now we can directly use parseUnits function to change value from ether to wei

const {ethers,formatUnits,parseUnits,JsonRpcProvider} =require('ethers');

value: parseUnits('0.01',"ether")

you can directly use parseUnit for conversion

0

If you are using ethers version 6 then you have to remove utils. you can directly use

ethers.parseEther("")

instead of ethers.utils.parseEther()

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.