Closed derawl closed 3 months ago
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.
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
Code
Search terms
hardhat ethers