Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signTypeData function not working for permit #4607

Open
Shimadakunn opened this issue Feb 16, 2024 · 0 comments
Open

signTypeData function not working for permit #4607

Shimadakunn opened this issue Feb 16, 2024 · 0 comments
Assignees
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6

Comments

@Shimadakunn
Copy link

Shimadakunn commented Feb 16, 2024

Ethers Version

6.10.0

Search Terms

permit

Describe the Problem

Hello,

I am trying to use the signTypeData function in order to create a ERC20 transaction with permit.
Here is what I have so fare

const writeContract = async (
    contractAddress: string,
    tokenAddress: string,
    contractABI: any,
    amount: string
  ) => {
    try {
      const ethersProvider = new ethers.BrowserProvider(provider as any);
      const signer = await ethersProvider.getSigner();
      const privateKey = await getPrivateKey();
      const wallet = new ethers.Wallet(privateKey, ethersProvider);
      const address = await signer.getAddress();
      const expiry = Math.floor(Date.now() / 1000) + 4200 ;

      const domain = {
        name: "Dai",
        version: '1',
        chainId: 11155111,
        verifyingContract: tokenAddress
      }
      const types = {
        Permit: [
          { name: "owner", type: "address" },
          { name: "spender", type: "address" },
          { name: "value", type: "uint256" },
          { name: "nonce", type: "uint256" },
          { name: "deadline", type: "uint256" },
        ],
      };
      const message = {
        owner: address,
        spender: contract,
        value: ethers.parseUnits(amount),
        nonce: 0,
        deadline: expiry,
      };
      const signature = await wallet.signTypedData(domain, types, message);
      return signature ;
    } catch (error: any) {
      return error as string;
    }
};

But when I execute the function I catch an error that follows:
TypeError: invalid ENS name (disallowed character: "["‎ {5B}) (argument="name", value="[object Object]", code=INVALID_ARGUMENT, version=6.10.0)

I don't understand which argument it refers to.

Can you help me to get the signature for this permit transaction? I need to get signature.v, signature.r, signature.s

@Shimadakunn Shimadakunn added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

2 participants