dmihal / eth-permit

Lightweight library for signing ERC-2612 permit signatures.
https://www.npmjs.com/package/eth-permit
139 stars 29 forks source link

'Dai/invalid-permit' #4

Open jrocco2 opened 3 years ago

jrocco2 commented 3 years ago

Im using this exact demo code while using Hardhat on a forked Ethereum mainnet node.

const result = await signDaiPermit(window.ethereum, tokenAddress, senderAddress, spender); await token.methods.permit(senderAddress, spender, result.nonce, result.expiry, true, result.v, result.r, result.s)

I'm able to console log all the variables and I tripled checked everything matches. However no matter what I do I always get the error message 'Dai/invalid-permit'

This is for the DAI token

jgostylo commented 1 year ago

I know this was posted a long time ago but I wanted to provide a possible answer. If you are deploying a DAI contract on your test fork then you need to make sure to deploy as chainId "31337". If you are using the DAI contract that was deployed on mainnet it was deployed as chainId "1". The DAI contract uses the DOMAIN_SEPARATOR pattern to ensure safety of transaction replay. If you are making a permit call on the mainnet deployment you need to sign the permit data with chainId=1, if you are making the permit call to a fresh deployment of DAI then you can use the provided chainId=31337. I am currently running into the issue that I cannot use Metamask to sign a message that claims chainId=1 when the active chainId=31337 because it is set up to refuse to do this (safety). However, I also cannot get the dai-permit library to use ethers to sign based on a wallet set up using chainId=1.