Sign Typed Data v4 error

v 6.1.8
react 18

Getting error when using Sign Typed Data v4 method

 const originalMessage = JSON.stringify({
                    domain,

                    // Defining the message signing data content.
                    message: {
                        /*
                           - Anything you want. Just a JSON Blob that encodes the data you want to send
                           - No required fields
                           - This is DApp Specific
                           - Be as explicit as possible when building out the message schema.
                          */
                        contents: "Hello, Bob!",
                        attachedMoneyInEth: 4.2,
                        from: {
                            name: "Cow",
                            wallets: ["0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826", "0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF"],
                        },
                        to: [
                            {
                                name: "Bob",
                                wallets: [
                                    "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
                                    "0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57",
                                    "0xB0B0b0b0b0b0B000000000000000000000000000",
                                ],
                            },
                        ],
                    },
                    // Refers to the keys of the *types* object below.
                    primaryType: "Mail",
                    types: {
                        // TODO: Clarify if EIP712Domain refers to the domain the contract is hosted on
                        EIP712Domain: [
                            { name: "name", type: "string" },
                            { name: "version", type: "string" },
                            { name: "chainId", type: "uint256" },
                            { name: "verifyingContract", type: "address" },
                        ],
                        // Not an EIP712Domain definition
                        Group: [
                            { name: "name", type: "string" },
                            { name: "members", type: "Person[]" },
                        ],
                        // Refer to PrimaryType
                        Mail: [
                            { name: "from", type: "Person" },
                            { name: "to", type: "Person[]" },
                            { name: "contents", type: "string" },
                        ],
                        // Not an EIP712Domain definition
                        Person: [
                            { name: "name", type: "string" },
                            { name: "wallets", type: "address[]" },
                        ],
                    },
                });

                const params = [eoaAddress, originalMessage];
                const method = "eth_signTypedData_v4";
                const signedMessage = await signer.provider.send(method, params)

hi @betnow

Trust you’re all doing well today … please let me check it and come back to you :slight_smile:

hi @betnow ,

I have no problem with the Ethers library example. Please check the RPC you are using (you can share with me all your configs) and also check that the Active chainId is the same one that you are using inside the domain/chain attribute in the message.

Domain

tconst domain = {
    name: 'Live Betting',
    version: '1.0.0',
    chainId: 137,
    verifyingContract: AZURO_CLIENT_CORE,
}

How signer is set

const connectHanlder = async () => {
    try {
      if (web3Auth) {
        const web3authProvider = await web3Auth.connect()
        if (web3authProvider) {
          hotjar.initialize(3306401, 6);
          setIsConnecting(true)
          const web3Provider = new ethers.providers.Web3Provider(web3authProvider);
          //const web3 = new Web3(web3authProvider);
          const signerVal = web3Provider.getSigner();
          const address = await signerVal.getAddress();
          const accountInfo = await web3Auth.getUserInfo();
          const isSocialLogin = Object.keys(accountInfo).length !== 0
          const biconomySmartAccountConfig = {
            signer: signerVal,
            chainId: ChainId.POLYGON_MAINNET,
            bundler: bundler,
            paymaster: paymaster,
            rpcUrl: getRpc(),
          };
          let biconomySmartAccount = new BiconomySmartAccount(
            biconomySmartAccountConfig
          );
          biconomySmartAccount = await biconomySmartAccount.init();
          const scwAddress = await biconomySmartAccount.getSmartAccountAddress()

          setEoaAddress(address?.toLowerCase())
          setSmartAccount(biconomySmartAccount);
          setProvider(web3Provider);
          setSigner(signerVal)
          setIsConnected(true);
          setSocailLogin(isSocialLogin)
          setProvider1(new ethers.providers.JsonRpcProvider(process.env.REACT_APP_POLYGON_RPC_URL_1))
          setProvider2(new ethers.providers.JsonRpcProvider(process.env.REACT_APP_POLYGON_RPC_URL_2))
          setProvider3(new ethers.providers.JsonRpcProvider(process.env.REACT_APP_POLYGON_RPC_URL_3))
          //setWeb3Val(web3);
          isSocialLogin ? setSocialInfo(accountInfo) : setSocialInfo(null)
          if (scwAddress?.length) {
            if (searchParams.get("referralID")?.length) {
              connectWalletAddress(scwAddress, searchParams.get("referralID"), isSocialLogin, accountInfo, address?.toLowerCase(), connectWalletCallBack)
            } else {
              connectWalletAddress(scwAddress, "", isSocialLogin, accountInfo, address?.toLowerCase(), connectWalletCallBack);
            }
          }
          setIsConnecting(false)
          return scwAddress;
        }
      } else return
    } catch (err) {
      setIsConnecting(false)
      //console.log(err, "here")
    }
  };

When i use signer.signMessage ,I’m able to get the signature but Sign Typed Data v4 is failing

hi @betnow

If you have an error with the RPC, can you share the URL you are using to connect?

also please update Ethers to the latest version

Thanks!

Rpc

https://polygon-mainnet.g.alchemy.com/v2/oQYTxK4aENs-

Sure will update ethers and let you know if it works

1 Like

@betnow Is your issue resolved?