Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidInputError: unknown account when impersonating signer #5403

Closed
derawl opened this issue Jun 18, 2024 · 1 comment
Closed

InvalidInputError: unknown account when impersonating signer #5403

derawl opened this issue Jun 18, 2024 · 1 comment
Assignees

Comments

@derawl
Copy link

derawl commented Jun 18, 2024

Version of Hardhat

2.6.4

What happened?

The error InvalidInputError: unknown account happens when I try to impersonate an account on the mainnet hardhat fork. I am not able to perform sign message operations with impersonated accounts.

Minimal reproduction steps

hardhat config network setup file

hardhat: {
      allowUnlimitedContractSize: true,
      forking: {
        url: `https://rpc.ankr.com/eth`,
        blockNumber: 16448948,
      },
    },

Code

const signer = await hardhatRuntime.ethers.getImpersonatedSigner(
    "0x8478F8c1d693aB4C054d3BBC0aBff4178b8F1b0B"
  );
  const signature = await signer.signMessage("message");

Search terms

hardhat ethers

@ChristopherDedominici
Copy link
Contributor

Hi @derawl, I tried to reproduce your issue but I did not manage. I'll share my code here so you can double-check if it also works for you. If not, could you please provide a code example that fails so I can try it in my environment?

First, check that your hardhatconfig.js file is correct. You have to provide the private key for the account that you want to impersonate. Here I generated a random private key:

require("@nomicfoundation/hardhat-toolbox");

module.exports = {
  defaultNetwork: "hardhat",
  networks: {
    hardhat: {
      forking: {
        url: `https://rpc.ankr.com/eth`,
        blockNumber: 16448948,
      },
      accounts: [
        {
          privateKey:
            "62b79e72a4d16784cb5e9763332370cb25b6ba99cb8da1081e0157fa489f086f",
          balance: "10000000000000000000000",
        },
      ],
    },
  },
  solidity: {
    version: "0.8.24",
  },
};

Then, you have to use the address associated to the private key that you want to use, in my case the address is: "0x739EEcFD0a6Ce561373081D435Be58786771C973".

describe("Deployment", function () {
  it("Should impersonate an account", async function () {
    const address = "0x739EEcFD0a6Ce561373081D435Be58786771C973";

    const signer = await hre.ethers.getImpersonatedSigner(address);
    const signature = await signer.signMessage("message");

    console.log(signature);
  });
});

If you copy, in a new hardhat project, this configuration in your hardhat.config.js file and this code in a test file, it should work fine.
I'm quite sure that the solution provided should fix your issue, so I'm closing it. If this is not the case, feel free to re-open it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants