0

I created a forked mainnet off Ethereum mainnet using my alchemy address and created the fork using Hardhat, I was able to see the fake contracts in the forked mainnet.

I'm running the following code using Hardhat and ethers on my Visual Studio code:

//Lesson 61 - Connecting to Mainnet Fork

     it("Send a transaction / swaps a Token", async () => {
        //const hre = require("hardhat")

        //const hre = require("hardhat");
        //const assert = require("assert");
        const [ownerSigner] = await ethers.providers.getSigners();
        console.log(ownerSigner); //Not working..!!

});

I ran npx hardhat test and I get the following error:

Read and Write to the Blockchain ✔ connects to a provider, factory, token, and a router 1937067327436140972299 This is amount.string ✔ Gets the Price of amountsOut (2639ms) 1) Send a transaction / swaps a Token

2 passing (3s) 1 failing

  1. Read and Write to the Blockchain Send a transaction / swaps a Token: TypeError: ethers.providers.getSigners is not a function at Context. (C:\Users\User\flashloanTest\hardhatTest\test\sendSwapTX.js:86:58) at processImmediate (node:internal/timers:478:21)

I've been struggling with this for a day now, any ideas please? High appreciate your help.

thanks in advance.

1 Answer 1

0

You can see the error is ethers.providers.getSigners is not a function

Change it to:

ethers.provider.getSigner() => signer

ethers.getSiger() => signer

ethers.getSigners() => signer[]

9
  • I tried with this: 'const [ownerSigner] = await ethers.getSigners();' i get error: 1) Read and Write to the Blockchain Send a transaction / swaps a Token: TypeError: (0 , ethers_1.getAddress) is not a function at new HardhatEthersSigner (node_modules\@nomicfoundation\hardhat-ethers\src\signers.ts:73:30) at Function.create (node_modules\@nomicfoundation\hardhat-
    – FuzzShak
    Commented Mar 7 at 9:49
  • I tried this: 'const [ownerSigner] = await ethers.getSigners()' i get the following error: 1) Read and Write to the Blockchain Send a transaction / swaps a Token: TypeError: (0 , ethers_1.getAddress) is not a function
    – FuzzShak
    Commented Mar 7 at 9:51
  • Could you post your git repo? I don't see any problem with your code.
    – CT95
    Commented Mar 8 at 7:39
  • Hi,Sure, here is my git repo - github.com/fuzzyshak/HardhatSwap/upload/main note: I installed hardhat using npm, then I installed ethersJS using 'npm install ethers^5.7.2 as this is the best version that works with the code.
    – FuzzShak
    Commented Mar 10 at 10:03
  • Here is a video showing the error: drive.google.com/file/d/1UoJLAfqV6m4r4HaF1MUAnRU2mm3k4w-A/…
    – FuzzShak
    Commented Mar 11 at 8:59

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.