I am attempting to call the "permit" function on the USDC contract on the Polygon Mumbai test network: here. Permit has the following function signature: function permit(address owner,address spender,uint256 value,uint256 deadline,uint8 v,bytes32 r,bytes32 s), from ERC-2612. In order to get the v, r, and s values, you must construct a signature, however it seems the signature I am getting is invalid. You can reproduce this with the following typescript code, using the Thirdweb SDK and ethers, npm i @thirdweb-dev/sdk ethers.
import { ThirdwebSDK } from "@thirdweb-dev/sdk"
import { ethers } from "ethers"
const sdk = ThirdwebSDK.fromPrivateKey('place your private key in here', "mumbai")
const message = {owner: 'place address of the wallet you are currently using', spender: 'place any address besides the one you are currently using', value: ethers.constants.MaxUint256, nonce: 0, deadline: ethers.constants.MaxUint256}
const {signature} = await sdk?.wallet.signTypedData(
{
name: "USD Coin (PoS)",
version: "1",
chainId: 80001,
verifyingContract: "0x0FA8781a83E46826621b3BC094Ea2A0212e71B23"
},
{
Permit: [
{ name: "owner", type: "address" },
{ name: "spender", type: "address" },
{ name: "value", type: "uint256" },
{ name: "nonce", type: "uint256" },
{ name: "deadline", type: "uint256" },
],
},
message
)
const split = ethers.utils.splitSignature(signature)
console.log(split)
Then call permit from mumbai.polygonscan (linked above) with any wallet and with the same parameters used to reproduce the error: invalid signature. What am I doing wrong here?
I have searched across the internet, tried many different approaches to generating the permit signature even outside of thirweb's sdk, but am still getting an invalid signature. The point of the permit function is to provide token spend approval in a gasless manner, and generating the proper signature is required. I expect the permit function to successfully execute with a valid signature, but I can't seem to generate a valid signature for permit. Please let me know if you would like me to include more details and or code, thank you in advance.
UPDATE: I have tried the same code on the ethereum USDC contract, changing the domain details of course, and the signature was valid. So it likely has something to do with the domain values I have set for Polygon USDC. I know permit can be called on this contract however because I have seen it successfully called in the transaction list.