Last active
December 8, 2024 12:40
-
-
Save ydm/69d110c87ffdb66bc5dab5a0bf5948f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ethers.js v5 | |
import { ethers, network } from "hardhat"; | |
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; | |
async function impersonate( | |
who: string, | |
f: (signer: SignerWithAddress) => Promise<void> | |
): Promise<void> { | |
await network.provider.request({ | |
method: "hardhat_impersonateAccount", | |
params: [who], | |
}); | |
const signer = await ethers.getSigner(who); | |
try { | |
await f(signer); | |
} finally { | |
network.provider.request({ | |
method: "hardhat_stopImpersonatingAccount", | |
params: [who], | |
}); | |
} | |
} |
// JavaScript
const { ethers, network } = require('hardhat');
async function impersonate(who, f) {
await network.provider.request({
method: 'hardhat_impersonateAccount',
params: [who],
});
const signer = await ethers.getSigner(who);
try {
await f(signer);
} finally {
network.provider.request({
method: 'hardhat_stopImpersonatingAccount',
params: [who],
});
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.