- raffle.sol
- vrfcoordinatorv2mock.sol
Я создал скрипты развертывания как: < /li>
/>01-deploy-raffle.js
Скрипт развертывания 01-deploy-raffle.js возвращает ошибку как:
vrfcoordinatorv2mock объект undefined < /strong>, что означает ethers.getContract ("vrfcoordinatorv2mock") < /strong> natefined. Это более позднее приводит к неверной ошибке адреса.01-deploy-raffer.js[/b]Код: Выделить всё
const { network, ethers } = require("hardhat") const {developmentChains} = require("../helper-hardhat-config") const BASE_FEE = ethers.parseEther("0.25")// 0.25 is the premium, it costs 0.25 LINKS per request const GAS_PRICE_LINK = 1e9 // calculated value based on gas price of chain 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!") await deploy("VRFCoordinatorV2Mock",{ from: deployer, log: true, args: args, }) log("Mock deployed!") log("-----------------------------------------------") } } module.exports.tags = ["all", "mocks"]hardhat.config.jsКод: Выделить всё
const { network, ethers } = require("hardhat") const { developmentChains, networkConfig } = require("../helper-hardhat-config") const { verify } = require("../utils/verify") const VRF_SUB_FUND_AMOUNT = ethers.parseEther("2") module.exports = async function ({ getNamedAccounts, deployments }) { const { deploy, log } = deployments const { deployer } = await getNamedAccounts() const chainId = network.config.chainId let vrfCoordinatorV2Address, subscriptionId if (developmentChains.includes(network.name)) { // get contract const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock") vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address console.log(`vrfCoordinatorV2Mock: ${vrfCoordinatorV2Mock.address}`) // here it prints undefined // create subscription const transactionResponse = await vrfCoordinatorV2Mock.createSubscription() const transactionReceipt = await transactionResponse.wait(1) /* USING LOGS TO GET THE SUBSCRIPTION ID AS THE events[0] way isn't working */ subscriptionId = BigInt(transactionReceipt.logs[0].topics[1]) // console.log("Full logs:", transactionReceipt.logs) console.log(`Subscription ID: ${subscriptionId}`) // Fund the subscription await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, VRF_SUB_FUND_AMOUNT) } else { vrfCoordinatorV2Address = networkConfig[chainId] subscriptionId = networkConfig[chainId]["subscriptionId"] } const entranceFee = networkConfig[chainId]["entranceFee"] const gasLane = networkConfig[chainId]["gasLane"] const callbackGasLimit = networkConfig[chainId]["callbackGasLimit"] const interval = networkConfig[chainId]["interval"] const arguments = [vrfCoordinatorV2Address, subscriptionId ,gasLane,interval,entranceFee ,callbackGasLimit] const raffle = await deploy("Raffle", { from: deployer, args: arguments, log: true, waitConfirmations: network.config.blockConfirmations || 1, }) if (!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) { log("Verifying...") await verify(raffle.address, args) } } module.exports.tags = ["all", "raffle"] < /code> Сообщение об ошибке: < /p> yarn run v1.22.22 $ /home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/.bin/hardhat deploy Nothing to compile Local network detecte! deploying "VRFCoordinatorV2Mock" (tx: 0x41a6ded59dc5ab1790aac807838abb66a002023d8f3d5b910834d549aeeae544)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 2967663 gas Mock deployed! ----------------------------------------------- vrfCoordinatorV2Mock: undefined Subscription ID: 1 An unexpected error occurred: Error: ERROR processing /home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/deploy/01-deploy-raffle.js: Error: invalid address (argument="address", value=undefined, code=INVALID_ARGUMENT, version=address/5.8.0) (argument="vrfCoordinatorV2", value=undefined, code=INVALID_ARGUMENT, version=abi/5.8.0) at Logger.makeError (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/logger/src.ts/index.ts:269:28) at Logger.throwError (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/logger/src.ts/index.ts:281:20) at Logger.throwArgumentError (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/logger/src.ts/index.ts:285:21) at AddressCoder.Coder._throwError (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/abi/src.ts/coders/abstract-coder.ts:68:16) at AddressCoder.encode (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/abi/src.ts/coders/address.ts:22:18) at /home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/abi/src.ts/coders/array.ts:71:19 at Array.forEach () at pack (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/abi/src.ts/coders/array.ts:54:12) at TupleCoder.encode (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/abi/src.ts/coders/tuple.ts:54:20) at AbiCoder.encode (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/abi/src.ts/abi-coder.ts:111:15) at DeploymentsManager.executeDeployScripts (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1215:19) at DeploymentsManager.runDeploy (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1061:5) at SimpleTaskDefinition.action (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/index.ts:450:5) at Environment._runTaskDefinition (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:351:14) at Environment.run (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:184:14) at SimpleTaskDefinition.action (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/index.ts:601:32) at Environment._runTaskDefinition (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:351:14) at Environment.run (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:184:14) at SimpleTaskDefinition.action (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/hardhat-deploy/src/index.ts:690:5) at Environment._runTaskDefinition (/home/user/blockchain/freecodecamp/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:351:14) error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.)Код: Выделить всё
require("@nomiclabs/hardhat-waffle") require("@nomiclabs/hardhat-etherscan") require("hardhat-deploy") // require("solidity-coverage") require("hardhat-gas-reporter") require("hardhat-contract-sizer") require("dotenv").config() // require("@nomicfoundation/hardhat-toolbox") const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL const PRIVATE_KEY = process.env.PRIVATE_KEY const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { defaultNetwork: "hardhat", networks: { hardhat: { chainId: 31337, blockConfirmations: 1, }, sepolia: { url: SEPOLIA_RPC_URL, accounts: [PRIVATE_KEY], chainId: 11155111, blockConfirmations: 6, }, }, solidity: { compilers: [ { version: "0.8.28", }, { version: "0.8.8", }, { version: "0.8.0", }, ], }, namedAccounts: { deployer: { default: 0, }, player: { default: 1, }, }, } < /code> Я пытался развернуть только 00-deploy-mocks.js с использованием yarn hardhat --tags mocks< /code> Script Script выполняется, как и ожидалось. и отпечатки: < /p> Nothing to compile Local network detecte! deploying "VRFCoordinatorV2Mock" (tx: 0x41a6ded59dc5ab1790aac807838abb66a002023d8f3d5b910834d549aeeae544)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 2967663 gas Mock deployed! < /code> Я подтвердил: < /strong> < /p> Скомпилируется контракт, а артефакт существует. < /li> Это развернуто через развертывание. Hardhat Clean
[*] hardhat: 2,23,0
[*] yarn: 1,22.22
[*] olidody: 0.8.28 (все по всему всем контрактам)
: 0.8.28 (все сроки. /> < /ul>
** Проблема: **
Почему Ethers.getContract ("vrfCoordinatorv2mock") возвращается не определенным, даже если контракт развернут и составлен?>
Подробнее здесь: https://stackoverflow.com/questions/796 ... ven-though