I am trying to test the contract but getting error:

  Basic NFT Unit Tests

      1) "before each" hook for "Initializes the NFT Correctly."

  0 passing (2s)
  1 failing

  1) Basic NFT Unit Tests
       "before each" hook for "Initializes the NFT Correctly.":
     Error: invalid contract address or ENS name (argument="addressOrName", value=undefined, code=INVALID_ARGUMENT, version=contracts/5.7.0)
      at Logger.makeError (node_modules\@ethersproject\logger\src.ts\index.ts:269:28)
      at Logger.throwError (node_modules\@ethersproject\logger\src.ts\index.ts:281:20)
      at Logger.throwArgumentError (node_modules\@ethersproject\logger\src.ts\index.ts:285:21)
      at Contract.BaseContract (node_modules\@ethersproject\contracts\src.ts\index.ts:712:20)
      at new Contract (node_modules\@ethersproject\contracts\lib\index.js:1053:42)
      at Function.ContractFactory.getContract (node_modules\@ethersproject\contracts\src.ts\index.ts:1297:16)
      at ContractFactory.attach (node_modules\@ethersproject\contracts\src.ts\index.ts:1260:42)
      at getContractAtFromArtifact (node_modules\@nomiclabs\hardhat-ethers\src\internal\helpers.ts:377:26)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at Context.<anonymous> (test\basicNft.test.js:15:26)`

Here, my code

const { assert } = require("chai")
const { network, deployments, ethers } = require("hardhat")
const { developmentChains } = require("../helper-hardhat-config")

    ? describe.skip
    : describe("Basic NFT Unit Tests", function () {
          let basicNft, deployer

          beforeEach(async () => {
              accounts = await ethers.getSigners()
              deployer = accounts[0]
              await deployments.fixture(["basicNft"])
              basicNft = await ethers.getContractAt("BasicNFT")
        describe("Constructor", () => {
            it("Initializes the NFT Correctly.", async () => {
                const name = await basicNft.name()
                const symbol = await basicNft.symbol()
                const tokenCounter=await basicNft.getTokenCounter()
                assert.equal(name, "Dogie")
                assert.equal(symbol, "DOG")

        describe("Mint NFT", () => {
          beforeEach(async () => {
              const txResponse = await basicNft.mintNft()
              await txResponse.wait(1)
          it("Allows users to mint an NFT, and updates appropriately", async function () {
              const tokenURI = await basicNft.tokenURI(0)
              const tokenCounter = await basicNft.getTokenCounter()

              assert.equal(tokenCounter.toString(), "1")
              assert.equal(tokenURI, await basicNft.TOKEN_URI())
          it("Show the correct balance and owner of an NFT", async function () {
              const deployerAddress = deployer.address;
              const deployerBalance = await basicNft.balanceOf(deployerAddress)
              const owner = await basicNft.ownerOf("0")

              assert.equal(deployerBalance.toString(), "1")
              assert.equal(owner, deployerAddress)

1 Answer 1


You are passing a faulty parameter in the getContractAt() function. It takes the contract name and address.

What you are trying to do here is connect to a deployed contract, but to achieve that, you need to provide the contract address.

Read more about it here.

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.