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

Error signing permit: TypeError: Do not know how to serialize a BigInt #4005

Closed
AmazingAng opened this issue Apr 26, 2023 · 7 comments
Closed
Assignees
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6

Comments

@AmazingAng
Copy link

Ethers Version

6.2.3

Search Terms

wallet, signTypedData

Describe the Problem

I met the following error when signing eip712 typed data with ethers.js v6:

Error signing permit: TypeError: Do not know how to serialize a BigInt

Code Snippet

async function signPermit() {
      const tokenAddress = "0x3317AD9eDa6942b5a7BE5BA83346C0Ea82C3C26C"; // Replace with your deployed ERC20Permit token contract address
      const chainId = 1; // Replace with the appropriate chain ID
      const tokenName = "MyToken"; // Replace with your token name
      const version = "1";
      const spender = "0x3317AD9eDa6942b5a7BE5BA83346C0Ea82C3C26C"; // Replace with the spender's address
      const value = ethers.parseUnits("10", 18); // Replace with the desired allowance value
      
      const provider = new ethers.BrowserProvider(window.ethereum)
      const signer = await provider.getSigner()
      const owner = await signer.getAddress();
      const nonce = 0; // Replace with the actual nonce for the owner
      const deadline = Math.floor(Date.now() / 1000) + 60 * 60 * 24; // 24 hours from now

      const domain = {
        name: tokenName,
        version: version,
        chainId: chainId,
        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: owner,
        spender: spender,
        value: value.toString(),
        nonce: nonce,
        deadline: deadline,
      };

      try {
        console.log(message)
        const signature = await signer.signTypedData(domain, types, message);
        console.log("Signature:", signature);
      } catch (error) {
        console.error("Error signing permit:", error);
      }
    }

Contract ABI

No response

Errors

Error signing permit: TypeError: Do not know how to serialize a BigInt

Environment

node.js (v12 or newer)

Environment (Other)

No response

@AmazingAng AmazingAng added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Apr 26, 2023
@ricmoo
Copy link
Member

ricmoo commented Apr 26, 2023

This was fixed in v6.3.0, see #3836 for more info. :)

@ricmoo ricmoo closed this as completed Sep 4, 2023
@elranu
Copy link

elranu commented Oct 3, 2023

Hi,
I still have it with Next.js
here is the repo to reproduce it: https://github.com/elranu/next-ethers/
code:
https://github.com/elranu/next-ethers/blob/main/src/app/info/route.ts

any idea why?? @ricmoo

@elranu
Copy link

elranu commented Oct 3, 2023

I have fix it with the following workaround: https://github.com/letoxyz/api-example/blob/main/src/patch.ts

@AmazingAng
Copy link
Author

I have fix it with the following workaround: https://github.com/letoxyz/api-example/blob/main/src/patch.ts

Use ethers > 6.3.0
You are using 6.2.3

@elranu
Copy link

elranu commented Oct 4, 2023

I have fix it with the following workaround: https://github.com/letoxyz/api-example/blob/main/src/patch.ts

Use ethers > 6.3.0 You are using 6.2.3

If you check the link of my first post you will see is 6.7.1. (https://github.com/elranu/next-ethers/blob/main/package.json) The other link is just the code I use to do a workaround. @AmazingAng

@serinuntius
Copy link

I have fix it with the following workaround: https://github.com/letoxyz/api-example/blob/main/src/patch.ts

Use ethers > 6.3.0 You are using 6.2.3

If you check the link of my first post you will see is 6.7.1. (https://github.com/elranu/next-ethers/blob/main/package.json) The other link is just the code I use to do a workaround. @AmazingAng

Same Problems. I used 6.7.1

@serinuntius
Copy link

I have fix it with the following workaround: https://github.com/letoxyz/api-example/blob/main/src/patch.ts

Use ethers > 6.3.0 You are using 6.2.3

If you check the link of my first post you will see is 6.7.1. (https://github.com/elranu/next-ethers/blob/main/package.json) The other link is just the code I use to do a workaround. @AmazingAng

Same Problems. I used 6.7.1

I'm sorry! My problem was another issue.

jestjs/jest#11617 (comment)

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

4 participants