Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

TypeError: contractAddresses[chainId].includes is not a function #194

Description

@kihiuFrank

I'm deploying my contract and I want to update the front-end with the contract addresses and the ABI.
But the update fails with the error below. What I'm I doing wrong?

Error

Updating front end...
An unexpected error occurred:

Error: ERROR processing /Users/k_frankline/projects/SaveAKid/backend/deploy/update-front-end.js:
TypeError: contractAddresses[chainId].includes is not a function
    at updateContractAddresses (/Users/k_frankline/projects/SaveAKid/backend/deploy/update-front-end.js:37:37)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Package.json

{
  "name": "SaveAKid",
  "version": "0.1.0",
  "private": true,
  "license": "MIT",
  "dependencies": {
    "hardhat": "^2.18.1"
  },
  "devDependencies": {
    "@chainlink/contracts": "^0.4.1",
    "@ethersproject/abi": "^5.4.7",
    "@ethersproject/providers": "^5.4.7",
    "@nomicfoundation/hardhat-chai-matchers": "^1.0.0",
    "@nomicfoundation/hardhat-ethers": "^3.0.2",
    "@nomicfoundation/hardhat-network-helpers": "^1.0.0",
    "@nomicfoundation/hardhat-toolbox": "^1.0.1",
    "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
    "@nomiclabs/hardhat-etherscan": "^3.0.0",
    "@typechain/ethers-v5": "^10.1.0",
    "@typechain/hardhat": "^6.1.2",
    "chai": "^4.2.0",
    "dotenv": "^16.0.2",
    "ethers": "^6.8.0",
    "hardhat-contract-sizer": "^2.10.0",
    "hardhat-deploy": "^0.11.14",
    "hardhat-gas-reporter": "^1.0.8",
    "prettier": "^2.7.1",
    "solhint": "^3.3.7",
    "solidity-coverage": "^0.8.2",
    "typechain": "^8.1.0"
  },
  "scripts": {
    "test": "hardhat test",
    "test:staging": "hardhat test --network rinkeby",
    "lint": "solhint 'contracts/*.sol'",
    "lint:fix": "solhint 'contracts/*.sol' --fix",
    "format": "prettier --write .",
    "coverage": "hardhat coverage"
  }
}

Update Frontend Script

const { network } = require("hardhat");
const fs = require("fs");
require("dotenv").config();

const {
  frontEndContractFile,
  frontEndAbiLocation,
} = require("../helper-hardhat-config");

module.exports = async function () {
  if (process.env.UPDATE_FRONT_END) {
    console.log("Updating front end...");
    await updateContractAddresses();
    await updateAbi();
  }
};

async function updateAbi() {
  const saveAKid = await ethers.getContract("SaveAKid");
  //   fs.writeFileSync(
  //     `${frontEndAbiLocation}SaveAKid.json`,
  //     saveAKid.interface.format(ethers.utils.FormatTypes.json)
  //   );
  fs.writeFileSync(
    frontEndAbiLocation,
    saveAKid.interface.format(ethers.FormatTypes.json)
  );
}

async function updateContractAddresses() {
  const saveAKid = await ethers.getContract("SaveAKid");
  const chainId = network.config.chainId.toString();
  const contractAddresses = JSON.parse(
    fs.readFileSync(frontEndContractFile, "utf8")
  );
  if (chainId in contractAddresses) {
    if (!contractAddresses[chainId].includes(saveAKid.address)) {
      contractAddresses[chainId].push(saveAKid.address);
    }
  } else {
    contractAddresses[chainId] = { SaveAKid: [saveAKid.address] };
  }
  fs.writeFileSync(frontEndContractFile, JSON.stringify(contractAddresses));
}

module.exports.tags = ["all", "frontend"];

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions