ethers.js – Fixing Overflow Error When Passing Wei Value to EIP712 _signTypedData

eip712ethers.jsoverflow

    const domainSeparator = {
        chainId: 5
    };
    
    const TestInfo = [
        { name: 'contractAddress', type: 'address' },
        { name: 'fee', type: 'uint256' }
      ];

    const data = {
        contractAddress: '.....',     
        airdropFee: 52009946125155410 // wei value
    };
    
    const signature = await signer._signTypedData(domainSeparator, { TestInfo }, data);

reason: 'overflow',
code: 'NUMERIC_FAULT',
fault: 'overflow',
operation: 'BigNumber.from',
value: 52009946125155410

solidity function takes uint256 wei value for weth amount as an argument, so I'm sending that number but getting overflow error. How do I fix that?

Best Answer

Your value 52009946125155410 is above the maximum integer safely representable as a Number type in JavaScript: 9007199254740991 so ethers.js throws an error.

Just pass it as a string :

airdropFee: "52009946125155410" // wei value

And it should be fine.

Related Topic