In my Hardhat test I'm trying to impersonate a USDC account so I can transfer USDC to a test address. The problem is no matter what address I try to impersonate, I always get the following error:
Error: VM Exception while processing transaction: reverted with reason string 'Blacklistable: account is blacklisted'
Here's the relevant code:
it("USDC Test", async function () {
const provider = ethers.provider;
const USDC = new ethers.Contract(addresses.tokens.usdc, abis.ERC20, provider);
// Impersonate USDC whale
await network.provider.request({
method: "hardhat_impersonateAccount",
params: [addresses.whales.usdc],
});
const usdcWhale = await ethers.provider.getSigner(addresses.whales.usdc);
// Approve and transfer USDC to test address
await USDC.connect(usdcWhale).approve(addresses.tokens.usdc, 10000);
await USDC.connect(usdcWhale).transfer(addresses.test.address1, 10000)
});
Any ideas on how to fix this error? I'm certain the addresses I'm using aren't actually blacklisted considering they recently transferred USDC on etherscan.
I realized my mistake. This line was causing the error:
await USDC.connect(usdcWhale).approve(addresses.tokens.usdc, 10000);
I originally thought I needed to approve the USDC contract itself to spend my tokens, however it's not needed if I'm just calling the transfer()
function.
Removing this line fixed the error.