[Ethereum] Impersonating accounts on a forked Ethereum main net using Hardhat

buidlergo-ethereummainnettokens

I used the example from the Hardhat docs to impersonate an account on a forked network:

await hre.network.provider.request({ method: "hardhat_impersonateAccount", params: ["0x...."]} )

However, I get "Error: Returned error: unknown account". How should this be done correctly? Thanks

Best Answer

try

import { network, ethers } from "hardhat";
await network.provider.request({
      method: "hardhat_impersonateAccount",
      params: ["0x..........................."],
    });

if you use hardhat-ethers

 const signer = await ethers.provider.getSigner(
      "0x..........................."
    );