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 initializing WalletConnect SDK [TypeError: Cannot read property 'getDefaultChain' of undefined] #5312

Closed
ozgurrgul opened this issue Aug 27, 2024 · 2 comments
Labels
type: bug Something isn't working

Comments

@ozgurrgul
Copy link

ozgurrgul commented Aug 27, 2024

Describe the bug
Getting the following error while trying to implement WC modal in react-native for Solana:

 INFO  {"context": "core"} Core Initialization Success
 INFO  {"context": "core"} {"context": "core/expirer"} Emitting expirer_deleted
 INFO  {"context": "client"} SignClient Initialization Success
 --> ERROR  Error initializing WalletConnect SDK [TypeError: Cannot read property 'getDefaultChain' of undefined]
 INFO  Cleaning up inactive pairings...
 INFO  Inactive pairings cleared: 0
 INFO  {"context": "core"} {"context": "core/relayer"} {"context": "core/relayer/subscription"} Emitting subscription_created
 INFO  {"context": "core"} {"context": "core/expirer"} Emitting expirer_created
 INFO  {"context": "core"} {"context": "core/history"} Emitting history_created
 INFO  {"context": "core"} {"context": "core/expirer"} Emitting expirer_created
 INFO  {"context": "client"} session request queue is empty.

Ethereum one works fine. What should I do to support Solana? I got the chain id from your SUPPORTED_CHAINS.md file

SDK Version (if relevant)

"ethers": "5.7.2",
"@walletconnect/encoding": "^1.0.2",
"@walletconnect/ethereum-provider": "2.15.1",
"@walletconnect/modal-react-native": "1.1.0",
"@walletconnect/react-native-compat": "2.15.1",
"@walletconnect/universal-provider": "2.15.1",
"react-native-url-polyfill": "^2.0.0",
"node-libs-react-native": "^1.2.1",
"react-native-get-random-values": "^1.11.0",

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
It should successfully open the modal

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: iOS (probably android too)
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context

Session params:

import { IProviderMetadata } from '@walletconnect/modal-react-native';
import { ISessionParams } from '@walletconnect/modal-react-native/lib/typescript/types/coreTypes';
import { NAVIGATION_SCHEMA } from '~/shared/environment';

export const WALLET_CONNECT_PROJECT_ID = '';

export const WALLET_CONNECT_METADATA: IProviderMetadata = {
  name: 'Omitted',
  description: 'Connect your wallet',
  url: 'https://Omitted.com/',
  icons: ['https://Omitted'],
  redirect: {
    native: `${NAVIGATION_SCHEMA}://`
  }
};

export const WALLET_CONNECT_SESSION_PARAMS: ISessionParams = {
  namespaces: {
    // Ethereum works fine
    // eip155: {
    //   methods: ['eth_signTransaction', 'eth_sign', 'personal_sign', 'eth_signTypedData'],
    //   chains: ['eip155:1'],
    //   events: ['accountsChanged']
    // },
    solana: {
      chains: ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'],
      methods: ['solana_signMessage', 'solana_signTransaction'],
      events: [],
      rpcMap: {
        '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp': 'https://api.mainnet-beta.solana.com'
       }
    }
  }
};

WalletConnectModal implementation (react native):

import React, { useMemo, useEffect, useState } from 'react';
import { useWalletConnectModal } from '@walletconnect/modal-react-native';
import { ethers } from 'ethers';
import { Props } from '@walletconnect/modal-react-native/lib/typescript/modal/wcm-modal';
import {
  WALLET_CONNECT_PROJECT_ID,
  WALLET_CONNECT_METADATA,
  WALLET_CONNECT_SESSION_PARAMS
} from '~/store/addressBook/web3/AddressBookWeb3Constants';
import { getSignPayload } from '~/store/addressBook/web3/AddressBookWeb3Utils';
import { actions } from '~/store/redux';
import { Steps } from '../ui/Steps';

export const WalletConnect = () => {
  const { open, isConnected, provider, address } = useWalletConnectModal();
  const [WalletConnectModal, setWalletConnectModal] = useState<((config: Props) => JSX.Element) | null>(null);
  const web3Provider = useMemo(() => (provider ? new ethers.providers.Web3Provider(provider) : undefined), [provider]);

  useEffect(() => {
    const loadWalletConnect = async () => {
      try {
        const { WalletConnectModal: WalletConnectModalComp } = await import('@walletconnect/modal-react-native');
        setWalletConnectModal(() => WalletConnectModalComp);
      } catch (error) {
        console.error('Failed to load WalletConnectModal:', error);
      }
    };

    setTimeout(loadWalletConnect, 500);
  }, []);

  const sign = async () => {
    if (!address) return;
    const signature = await web3Provider?.send('personal_sign', [getSignPayload(), address]);
    // make use of signature
  };

  const disconnect = () => {
    provider?.disconnect();
  };

  const getContent = () => {
    if (!WalletConnectModal) {
      return <Steps.Loading />;
    }

    if (isConnected) {
      return <Steps.Connected onPressOpenWallet={sign} onPressDisconnect={disconnect} />;
    }

    return <Steps.NotConnected onPressOpenWallet={open} />;
  };

  return (
    <>
      {getContent()}
      {WalletConnectModal ? (
        <WalletConnectModal
          projectId={WALLET_CONNECT_PROJECT_ID}
          providerMetadata={WALLET_CONNECT_METADATA}
          sessionParams={WALLET_CONNECT_SESSION_PARAMS}
        />
      ) : null}
    </>
  );
};
@ozgurrgul ozgurrgul added the type: bug Something isn't working label Aug 27, 2024
@ozgurrgul
Copy link
Author

closing since we will switch to web3modal (appKit)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant