Hello, Team how are you doing?
I'm creating the signature for ERC20Permit offline and when i pass the following parameters to the permit function it throws error 'invalid signature'. Can you please look over the code what i'm doing wrong?
It is the code which i write in testcase which simply deploys the contract Erc20 create the signature offchain pass it to ERC20Permit's permit function via Erc20 Contract (MyToken)
Erc20 like
contract MyToken is ERC20, ERC20Burnable, Pausable, Ownable, ERC20Permit {
.
.
}
Testcase
it.only('should create the signature for verification', async function (){
const { MyToken, owner } = await loadFixture(deployContractsAndReturnInstances);
const signer = owner;
const domainData = {
name: "MYTOKEN",
version: "1.0.0",
chainId: 31337,
verifyingContract: MyToken.address,
};
const deadline = ethers.constants.MaxUint256;
const nonce = 0;
const val=1;
const types = {
Permit: [
{name:'owner',type:'address'},
{name:'spender',type:'address'},
{name:'value',type:'uint256'},
{name:'nonce',type:'uint256'},
{name:'deadline',type:'uint256'},
]
};
const value = {
owner:owner.address,
spender:MyToken.address,
value:val,
nonce: nonce,
deadline,
};
const result = await signer._signTypedData(domainData, types, value);
let sig = ethers.utils.splitSignature(result);
const {v, r, s} = sig;
const data = await MyToken.permit(owner.address,MyToken.address,val,deadline,v,r,s);
})