Skip to content

Instantly share code, notes, and snippets.

@developeruche
Last active January 18, 2023 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save developeruche/1660097d81747e029e9ee01907dc679c to your computer and use it in GitHub Desktop.
Save developeruche/1660097d81747e029e9ee01907dc679c to your computer and use it in GitHub Desktop.
async function getPermitSignature(signer: any, token: any, spender: any, value: any, deadline: any) {
const [nonce, name, version, chainId] = await Promise.all([
token.nonces(signer.address),
token.name(),
"1",
80001,
])
console.log(nonce, name, version, chainId)
return ethers.utils.splitSignature(
await signer._signTypedData(
{
name,
version,
chainId,
verifyingContract: token.address,
},
{
Permit: [
{
name: "owner",
type: "address",
},
{
name: "spender",
type: "address",
},
{
name: "value",
type: "uint256",
},
{
name: "nonce",
type: "uint256",
},
{
name: "deadline",
type: "uint256",
},
],
},
{
owner: signer.address,
spender,
value,
nonce,
deadline,
}
)
)
}
const deadline = Math.floor(Date.now() + 600);
const { v, r, s } = await getPermitSignature(
contractOwner,
Token,
DIAMOND_ADDRESS,
NUM_IN,
deadline
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment