I deployed this ERC20 + ERC20Permit contract on Avalanche Fuji(43313) and pre-minted 900000
tokens.
- I prepare a permit request to be signed by the owner.
// Prepare Contract
let tokenContract = IERC20Permit__factory.connect(tokenAddress, provider);
let tokenChainId = await tokenContract.provider.getNetwork().then((n) => n.chainId);
const getPermitNonce = await tokenContract.nonces(playerPubkey);
const permitNonce = getPermitNonce.toString();
// Grabs the current timestamp
const blockNumber = await provider.getBlockNumber();
const block = await provider.getBlock(blockNumber);
const timestamp = block.timestamp;
// set the Permit type values
const permitRequest = {
owner: '0x469443b1A8e764543C46F304272273ECBBB1d5E9',
spender: '0x83bF103738373B3565d75C9c0C32894B563bA234',
value: '3000',
nonce: permitNonce, // '0'
deadline: timestamp + 600, // Valid for 10 minutes
};
// set the Permit type parameters
const PermitRequestType = [
{
name: "owner",
type: "address"
},
{
name: "spender",
type: "address"
},
{
name: "value",
type: "uint256"
},
{
name: "nonce",
type: "uint256"
},
{
name: "deadline",
type: "uint256"
},
];
// set the domain parameters
const PermitTypedData = {
domain: {
name: tokenName,
version: "1",
chainId: tokenChainId,
verifyingContract: tokenContract.address
},
primaryType: "PermitRequest",
types: {
PermitRequest: PermitRequestType
}
};
const toSignPermit = { ...PermitTypedData, message: permitRequest };
-
I then sign the request using the owner signer
0x469443b1A8e764543C46F304272273ECBBB1d5E9
-
Split signature:
// sig
r: '0xe8f78de1c311183e3d931c1cd7a55154c281df301a1f6852f0105b2b1f0d483f',
s: '0x5efcea0b9778818daae2c9b89bc5d395321fe42a546fb75c602126cc507945ef',
_vs: '0xdefcea0b9778818daae2c9b89bc5d395321fe42a546fb75c602126cc507945ef',
recoveryParam: 1,
v: 28,
yParityAndS: '0xdefcea0b9778818daae2c9b89bc5d395321fe42a546fb75c602126cc507945ef',
compact: '0xe8f78de1c311183e3d931c1cd7a55154c281df301a1f6852f0105b2b1f0d483fdefcea0b9778818daae2c9b89bc5d395321fe42a546fb75c602126cc507945ef'
const permit = await tokenContract.permit(toSignPermit.message.owner, toSignPermit.message.spender, toSignPermit.message.value, toSignPermit.message.deadline, sig.v, sig.r, sig.s, { gasLimit: 1000000 });
Here is the failed transaction you can decode input data and double check out my request params,