2

I'm encountering a TypeError in my Hardhat test script that involves the isAddress function from the @nomicfoundation/hardhat-chai-matchers library. The error seems to be causing issues with my test suite. Below is the relevant code snippet: here my code.

const { expect, assert } = require("chai");
const { ethers } = require("hardhat");

const {
  addressFactory,
  addressRouter,
  addressFrom,
  addressTo,
} = require("../utils/AddressList");

const { erc20ABI, factoryABI, routerABI } = require("../utils/AbiList");

describe("read and write blockchain", () => {
  let provider,
    contractFactory,
    contractRouter,
    contractToken,
    decimals,
    amountIn,
    amountOut;

  provider = new ethers.providers.JsonRpcProvider(
      ""
    );
    contractFactory = new ethers.Contract(addressFactory, factoryABI, provider);
    contractRouter = new ethers.Contract(addressRouter, routerABI, provider);
    contractToken = new ethers.Contract(addressFrom, erc20ABI, provider);
  });

  it("connects to the provider, factory, token, and router", () => {
    assert(provider._isProvider);

    expect(contractFactory.address).to.equal(
      "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"
    );
    expect(contractRouter.address).to.equal(
      "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
    );
    expect(contractToken.address).to.equal(
      "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
    );
  });
});

Full error

`read and write blockchain
    1) connects to the provider, factory, token, and router


  0 passing (96ms)
  1 failing

  1) read and write blockchain
       connects to the provider, factory, token, and router:
     TypeError: (0 , ethers_1.isAddress) is not a function
      at tryGetAddressSync (node_modules/@nomicfoundation/hardhat-chai-matchers/src/internal/addressable.ts:29:16)
      at Proxy.<anonymous> (node_modules/@nomicfoundation/hardhat-chai-matchers/src/internal/addressable.ts:53:20)
      at Proxy.overwritingMethodWrapper (node_modules/chai/lib/chai/utils/overwriteMethod.js:78:33)
      at Proxy.<anonymous> (node_modules/@nomicfoundation/hardhat-chai-matchers/src/internal/bigNumber.ts:193:14)
      at Proxy.overwritingMethodWrapper (node_modules/chai/lib/chai/utils/overwriteMethod.js:78:33)
      at doAsserterAsyncAndAddThen (node_modules/chai-as-promised/lib/chai-as-promised.js:289:22)
      at Proxy.<anonymous> (node_modules/chai-as-promised/lib/chai-as-promised.js:255:20)
      at Proxy.overwritingMethodWrapper (node_modules/chai/lib/chai/utils/overwriteMethod.js:78:33)
      at Context.<anonymous> (test/SendSwapTx.js:32:40)`
2
  • Hi! Could you provide the full error traceback? (Also, you have an API key in your code, please scrub it, for your sake.) Jan 2 at 18:40
  • I added full error
    – Aung
    Jan 2 at 23:22

1 Answer 1

0

It is likely that your version of ethers.js is not compatible with the version of chai that you are using. I would assume that you are using [email protected] in this project for JsonRpcProvider to work. I reinstalled [email protected] so that all depencies would be compatible. I'll attach a package.json that should work for you.

 {
  "name": "hardhattutorial",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@nomiclabs/hardhat-ethers": "^2.0.5",
    "@nomiclabs/hardhat-waffle": "^2.0.3",
    "chai": "^4.3.6",
    "ethereum-waffle": "^3.4.4",
    "ethers": "^5.6.5",
    "hardhat": "^2.9.3"
  },
  "dependencies": {
    "@nomicfoundation/hardhat-toolbox": "^2.0.2"
  }
}

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.