I'm struggling to figure out why I'm getting EIP2612: invalid signature when attempting to generate a signature for one chain (polygon mainnet) vs another (polygon mumbai). On mumbai, I have no issues. As soon as I pass in the mainnet chainId, I keep getting the invalid signature message.
Here's my sign function:
import { Contract, Signature, TypedDataDomain } from "ethers";
export const sign = async (
signer,
tokenContract,
value,
spenderAddress,
deadline,
chainId
) => {
const domain = {
name: await tokenContract.name(),
version: await tokenContract.version(),
verifyingContract: token.target.toString(),
chainId,
};
const types = {
Permit: [
{ name: "owner", type: "address" },
{ name: "spender", type: "address" },
{ name: "value", type: "uint256" },
{ name: "nonce", type: "uint256" },
{ name: "deadline", type: "uint256" },
],
};
const address = await signer.getAddress();
const data = {
owner: address,
spender: spenderAddress,
value: value,
nonce: await token.nonces(address),
deadline: deadline,
};
try {
let sig;
// annoying hardhat naming inconsistencies
if (signer._signTypedData === undefined) {
sig = await signer.signTypedData(domain, types, data);
} else {
sig = await signer._signTypedData(domain, types, data);
}
return Signature.from(sig);
} catch (e) {
console.error("Error generatig permit signature", e);
return Promise.reject("Error generating permit signature");
}
};
FWIW, the token in question is USDC. This is the contract I'm targeting: 0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359
.
Again, I have no issues on mumbai (chainId: 80001). It's when I try polygon mainnet (chainId: 137), where things start breaking.
Any help in debugging would be greatly appreciated.