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

Cannot connect to Irys using Wallet Connect #21

Open
nixjs opened this issue Feb 4, 2025 · 4 comments
Open

Cannot connect to Irys using Wallet Connect #21

nixjs opened this issue Feb 4, 2025 · 4 comments

Comments

@nixjs
Copy link

nixjs commented Feb 4, 2025

I used my phone to scan wallet connect. It connected to the wallet but couldn't connect to Irys.
This is my code:

'use client'

import React from 'react'
import BaseWebIrys from '@irys/web-upload/esm/base'
import { useAppKitAccount, useAppKitNetwork } from '@reown/appkit/react'
import { WebUploader } from '@irys/web-upload'
import { sepolia, mainnet } from 'viem/chains'
import { createWalletClient, createPublicClient, custom } from 'viem'
import { ViemV2Adapter } from '@irys/web-upload-ethereum-viem-v2'
import { ContextState, IrysContext } from './useIrysUploader'
import { toastWarning } from '@/toast'
import { ChainById, TransportByChainId } from '@/config/wallet'
import { IrysWebUploader, IrysWebUploaderExtends } from '@/config/irys'
import useMode from '@/hooks/useMode'
import { useAppState } from '@/store/useAppStore'
import { useMediaState } from '@/store/useMediaStore'

const IrysUploaderProvider = ({ children }: { children?: React.ReactNode }) => {
    const [irys, setIrys] = React.useState<BaseWebIrys | null>(null)
    const { isConnected } = useAppKitAccount()
    const { chainId } = useAppKitNetwork()
    const { mode } = useAppState()
    const { constructableWebTokenFund } = useMediaState()
    const { fetchMode } = useMode()

    React.useEffect(() => {
        fetchMode()
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [])

    React.useEffect(() => {
        const connectIrys = async () => {
            try {
                console.log('Network changed', mode)
                const isDev = mode === 'devnet'
                const isDesktop = typeof window.ethereum !== 'undefined'
                const fChainId = Number(
                    chainId
                ) as unknown as keyof typeof ChainById
                const chain = fChainId
                    ? ChainById[fChainId]
                    : isDev
                      ? sepolia
                      : mainnet

                const transport = isDesktop
                    ? custom((window as any).ethereum)
                    : TransportByChainId[fChainId]
                const provider = createWalletClient({
                    chain,
                    transport
                })

                const publicClient = createPublicClient({
                    chain: sepolia,
                    transport
                })

                const webUploader = constructableWebTokenFund
                    ? IrysWebUploaderExtends[constructableWebTokenFund]
                    : IrysWebUploader[fChainId]

                const irysUploader = await WebUploader(webUploader)
                    .withAdapter(
                        ViemV2Adapter(provider, {
                            publicClient
                        })
                    )
                    .network(mode)
                if (irysUploader) {
                    console.log(
                        `Connected to Irys: ${irysUploader.address}`,
                        irysUploader.url
                    )
                    setIrys(irysUploader)
                } else toastWarning('Failed to connect irys')
            } catch (error) {
                // toast(<div>{JSON.stringify(error)}</div>)
                toastWarning('Error connecting to Irys')
                console.error('Error connecting to Irys:', error)
            }
        }
        if (isConnected && chainId && mode) {
            connectIrys()
        }
    }, [isConnected, mode, chainId, constructableWebTokenFund])

    const value: ContextState = {
        irysUploader: irys,
        irysAddress: irys?.address ?? ''
    }

    return <IrysContext.Provider value={value}>{children}</IrysContext.Provider>
}

export default IrysUploaderProvider

This is error:

Image
@JesseTheRobot
Copy link
Member

Are you able to provide the full error stacktrace?

@nixjs
Copy link
Author

nixjs commented Feb 11, 2025

Are you able to provide the full error stacktrace?

This is source code: https://github.com/nixjs/next-irys
Steps:

  1. Run code: pnpm dev
  2. Click Connect wallet button
  3. Choose provider Wallet Connect
  4. Use wallet on phone (i used Trust wallet), then scan QR.
  5. Error below appears as video

I found out that the error is in package @irys/web-upload-ethereum, the part related to the InjectedTypedEthereumSigner method.

Screen.Recording.2025-02-11.at.17.24.33.mov

@JesseTheRobot
Copy link
Member

JesseTheRobot commented Feb 11, 2025

I found out that the error is in package @irys/web-upload-ethereum, the part related to the InjectedTypedEthereumSigner method.

which method? if you tell me which I can probably figure this out pretty quickly (or just post a screenshot of the line & some context, even if it's the transpiled JS and not TS)

@nixjs
Copy link
Author

nixjs commented Feb 11, 2025

I found out that the error is in package @irys/web-upload-ethereum, the part related to the InjectedTypedEthereumSigner method.

which method? if you tell me which I can probably figure this out pretty quickly (or just post a screenshot of the line & some context, even if it's the transpiled JS and not TS)

You can run the source code on my github and connect wallet to see the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@JesseTheRobot @nixjs and others