3

I've written very basic code to connect Ethereum Mainnet with Web3modal Standalone client after scan QR code getting below SS error.

I've also followed this blog https://medium.com/walletconnect/walletconnect-sign-v2-0-beginners-guide-for-javascript-developers-c02c02d215c9 but can't get it to work.

I've also deployed it here: https://fiverr-push-test.web.app/

Error SS

enter image description here

Code

import SignClient from "@walletconnect/sign-client";
import { Web3Modal } from "@web3modal/standalone";
import { useEffect, useState } from "react";


const projectId = "CAN NOT WRITE KEY HERE";


const web3Modal = new Web3Modal({
  projectId: projectId,
  standaloneChains: ["eip155:1"],
});

export default function HomePage() {
  const [signClient, setSignClient] = useState(undefined);

  // 3. Initialize sign client
  async function onInitializeSignClient() {
    const client = await SignClient.init({
      projectId: projectId,
    });
    setSignClient(client);
  }

  // 4. Initiate connection and pass pairing uri to the modal
  async function onOpenModal() {
    if (signClient) {
      const namespaces = {
        eip155: {
          methods: ["eth_sendTransaction"],
          chains: ["eip155:1"],
          events: ["connect", "disconnect"],
        },
      };
      const { uri, approval } = await signClient.connect({
        requiredNamespaces: namespaces,
      });
      console.log(uri);
      if (uri) {
        try {
          await web3Modal.openModal({
            uri,
            standaloneChains: namespaces.eip155.chains,
          });
          console.log(namespaces.eip155.chains);
          await approval();
          console.log(22222);
          web3Modal.closeModal();
        } catch (error) {
          console.log("Eeee", error);
        }
      }
    }
  }

  useEffect(() => {
    if (!signClient) {
      onInitializeSignClient();
    }
  }, []);

  return signClient ? (
    <button onClick={onOpenModal}>Connect Wallet</button>
  ) : (
    "Initializing..."
  );
}

Mitul Lakhani
  • 182
  • 1
  • 12

0 Answers0