Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.
This repository was archived by the owner on May 16, 2024. It is now read-only.

bug: How to combine different public clients with useWagmiPlugin? #55

Closed

Description

@dataexcess

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

0.3.7

Current Behavior

Hello!

I am using web3Modal as my connector inside the use-wagmi.ts plugin:

import { UseWagmiPlugin, configureChains, createConfig, mainnet, sepolia } from 'use-wagmi'
import { publicProvider } from 'use-wagmi/providers/public'
import { infuraProvider } from 'use-wagmi/providers/infura'
import { EthereumClient, w3mConnectors, w3mProvider } from '@web3modal/ethereum'
import { Web3Modal } from '@web3modal/html'

export default defineNuxtPlugin((nuxtApp) => {
    const config = useRuntimeConfig()
    const projectId = config.public.WALLETCONNECT_PROJECT_ID
    const infuraKey = config.public.INFURA_API_KEY
    const chains = [mainnet, sepolia]

    const { publicClient } = configureChains(chains,
        [w3mProvider({ projectId }), infuraProvider({ apiKey: infuraKey }), publicProvider()]
    )

    const web3config = createConfig({
        autoConnect: true,
        connectors: w3mConnectors({ projectId, chains }),
        publicClient
    })

    let web3Modal = null
    if (process.client) {
        const ethereumClient = new EthereumClient(web3config, chains)
        web3Modal = new Web3Modal({ projectId }, ethereumClient)
    }

    nuxtApp.vueApp.use(UseWagmiPlugin, web3config)

    return {
        provide: {
            web3Modal
        }
    }
})

The problem is that, using the web3modal connection, I cannot query any data from the blockchain before the user connects the wallet. The public client relies on the connection made by the wallet. But I want to be able to execute readContract before the user connects (to display all tokens of my nft collection...). How can I accomplish this? Do I need to make a separate publicClient (that simply uses Public or infura provider)? But how can I switch it sothat it uses the UseWagmiPlugin? What would you recommend?

Thank you for the help!

Expected Behavior

No response

Steps To Reproduce

No response

Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)

No response

Anything else?

No response

Activity

  1. unicape commented on Aug 11, 2023

    @unicape
    Owner

    @dataexcess If you can suggest you implement your own useContractRead

  2. Repository owner locked and limited conversation to collaborators on Aug 11, 2023
  3. converted this issue into a discussion #56 on Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions