Lesson 9 Lottery: unable to deploy contracts, via deployment script. ERROR: TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider') #5656
-
I ran > yarn hardhat deploy., and i recieved an error message: This is my 01-deploy-raffle.js const { network } = require("hardhat");
const { developmentChains } = require("../helper-hardhat-config");
// you need these two variables cuz, when we deploy the V2Mock contract, we need to input these 2 arguments, which will go into the contract's constructor.
const BASE_FEE = ethers.utils.parseEther("0.25"); // cost 0.25 link per request. Seen from: https://docs.chain.link/vrf/v2/subscription/supported-networks
const GAS_PRICE_LINK = 1e9; //calculated value based on the gas price of the chain. (link per Gas) so the keepers get compensated for GAS paid to run the contract on certain time.
module.exports = async function ({ getNamedAccounts, deployments }) {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts;
const args = [BASE_FEE, GAS_PRICE_LINK];
if (developmentChains.includes(network.name)) {
log("Local network detected! Deploying mocks");
// deploy a mock vrfcoordinator..
await deploy("VRFCoordinatorV2Mock", {
from: deployer,
log: true,
args: args, // we can see from the github that the VRFCoordinatorV2Mock.sol contract's constructor take in 2 arguments.
});
log("Mocks Deployed!");
log("------------------------------------------");
}
};
module.exports.tags = ["all", "mocks"]; My hardhat.config.js: require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-etherscan");
require("@nomiclabs/hardhat-ethers");
require("hardhat-deploy");
require("solidity-coverage");
require("hardhat-gas-reporter");
require("hardhat-contract-sizer");
require("dotenv").config();
/** @type import('hardhat/config').HardhatUserConfig */
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const USER1_PK = process.env.USER1_PK;
const CMC_API_KEY = process.env.CMC_API_KEY;
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
module.exports = {
defaultNetwork: "hardhat",
networks: {
hardhat: {
chainId: 31337,
blockConfirmations: 1,
},
sepolia: {
chainId: 11155111,
blockConfirmations: 6,
url: SEPOLIA_RPC_URL,
accounts: [PRIVATE_KEY, USER1_PK],
},
},
solidity: "0.8.18",
namedAccounts: {
deployer: {
default: 0,
},
player: {
default: 1,
},
},
}; My helper-config.js: const { network } = require("hardhat");
const { developmentChains } = require("../helper-hardhat-config");
// you need these two variables cuz, when we deploy the V2Mock contract, we need to input these 2 arguments, which will go into the contract's constructor.
const BASE_FEE = ethers.utils.parseEther("0.25"); // cost 0.25 link per request. Seen from: https://docs.chain.link/vrf/v2/subscription/supported-networks
const GAS_PRICE_LINK = 1e9; //calculated value based on the gas price of the chain. (link per Gas) so the keepers get compensated for GAS paid to run the contract on certain time.
module.exports = async function ({ getNamedAccounts, deployments }) {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts;
const args = [BASE_FEE, GAS_PRICE_LINK];
if (developmentChains.includes(network.name)) {
log("Local network detected! Deploying mocks");
// deploy a mock vrfcoordinator..
await deploy("VRFCoordinatorV2Mock", {
from: deployer,
log: true,
args: args, // we can see from the github that the VRFCoordinatorV2Mock.sol contract's constructor take in 2 arguments.
});
log("Mocks Deployed!");
log("------------------------------------------");
}
};
module.exports.tags = ["all", "mocks"]; I tried to remove my node_modules, and reinstalling it, but still have the same issue. Thanks to whoever who can help out ! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
@Glow-in-the-dark new version of ethers have this issue, use ethers version:5.4.1, it will work |
Beta Was this translation helpful? Give feedback.
-
@Glow-in-the-dark in your both deploy scripts you need to require ethers from hardhat add this below line in your both deploy scripts at top const { ethers } = require("hardhat") and also you need to downgrade your ethers version so write below command in your terminal |
Beta Was this translation helpful? Give feedback.
-
@Glow-in-the-dark in your const { deployer } = await getNamedAccounts; with this one const { deployer } = await getNamedAccounts(); |
Beta Was this translation helpful? Give feedback.
@Glow-in-the-dark in your both deploy scripts you need to require ethers from hardhat add this below line in your both deploy scripts at top
and also you need to downgrade your ethers version so write below command in your terminal
yarn add ethers@5.4.0