6

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

2 Answers 2

8

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..........................."
    );
7

Update Oct 2022

Impersonating Accounts with Hardhat has a new, simplified API. According to their new docs, you can impersonate an account using the getImpersonatedSigner method

const impersonatedSigner = await ethers.getImpersonatedSigner("0x1234567890123456789012345678901234567890");
await impersonatedSigner.sendTransaction(...);

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.