Open
Description
Lesson
Lesson 10
Could you please leave a link to the timestamp in the video where this error occurs? (You can right click a video and "copy video URL at current time")
No response
Operating System
Windows
Describe the bug
please when i deploy on my local host the Abi and contractAddress are writing to the Abi.json and contractaddress.json files, but when i deploy to sepolia it doesnt write. this is my code
const { ethers, network } = require("hardhat");
const fs = require("fs");
const ADDRESS_FILE = "../nextjslottery/constants/contractAddress.json";
const ABI_FILE = "../nextjslottery/constants/abi.json";
module.exports = async function () {
if (process.env.UPDATE_FRONT_END) {
console.log("updating front end...");
updateContractAddress();
console.log("updatedd");
updateAbi();
}
};
async function updateAbi() {
const raffle = await ethers.getContract("Raffle");
console.log(JSON.stringify(raffle.interface.fragments));
fs.writeFileSync(ABI_FILE, JSON.stringify(raffle.interface.fragments));
}
async function updateContractAddress() {
const raffle = await ethers.getContract("Raffle");
const chainId = network.config.chainId.toString();
console.log("ChainId:", chainId);
const currentAddress = JSON.parse(fs.readFileSync(ADDRESS_FILE, "utf8"));
if (chainId in currentAddress) {
if (!currentAddress[chainId].includes(raffle.target)) {
currentAddress[chainId].push(raffle.target);
}
}
{
currentAddress[chainId] += [raffle.target];
}
fs.writeFileSync(ADDRESS_FILE, JSON.stringify(currentAddress));
}
module.exports.tags = ["all", "frontend"];
this is my hardhat.config.js
//require("@nomicfoundation/hardhat-toolbox");
//require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-ethers");
require("dotenv").config();
//require("./tasks/block-number");
require("hardhat-gas-reporter");
require("solidity-coverage");
require("hardhat-deploy");
require("hardhat-contract-sizer");
require("@nomiclabs/hardhat-etherscan");
require("dotenv").config();
require("@nomicfoundation/hardhat-chai-matchers");
/** @type import('hardhat/config').HardhatUserConfig */
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL || "https://eth-sepolia";
const PRIVATE_KEY = process.env.PRIVATE_KEY || "0xkey";
const ETHERSCAN_APIKEY = process.env.ETHERSCAN_APIKEY || "key";
const COINMARKETCAP_KEY = process.env.COINMARKETCAP_KEY || "key";
module.exports = {
defaultNetwork: "hardhat",
networks: {
sepolia: {
url: "https://eth-sepolia.g.alchemy.com/v2/OkYrqR39tJtHfjUzXb8qdaasT8kyvvrH",
accounts: [PRIVATE_KEY],
chainId: 11155111,
blockConfirmations: 6,
},
localhost: {
url: "http://127.0.0.1:8545/",
chainId: 31337,
blockConfirmations: 6,
},
},
solidity: {
compilers: [
{
version: "0.8.24",
},
{
version: "0.7.7",
settings: {},
},
],
},
namedAccounts: {
deployer: {
default: 0,
},
player: {
default: 1,
},
},
gasReporter: {
enabled: false,
outputFile: "gas-report.txt",
noColors: true,
currency: "USD",
coinmarketcap: COINMARKETCAP_KEY,
token: "ETH",
},
etherscan: {
apiKey: {
sepolia: ETHERSCAN_APIKEY,
},
},
mocha: {
timeout: 400000, //400 seconds
},
};