使用 React 连接到元掩码,Next.js 不起作用

发布于 2025-01-10 11:55:16 字数 1253 浏览 0 评论 0原文

我正在遵循使用 Next.js 构建 NFT 市场的指南。我被困在构建一个应该打开元掩码的按钮的部分。据我了解 'connectWallet('injected')' 应该打开元掩码,但对我来说,什么也没有发生。甚至没有错误消息。这里可能有什么问题?

import type { NextPage } from 'next'
import Header from '../components/Header'
import Hero from '../components/Hero'
import { useWeb3 } from '@3rdweb/hooks'

const style = {
  wrapper: ``,
  walletConnectWrapper: `flex flex-col justify-center items-center h-screen w-screen bg-[#3b3d42] `,
  button: `border border-[#282b2f] bg-[#2081e2] p-[0.8rem] text-xl font-semibold rounded-lg cursor-pointer text-black`,
  details: `text-lg text-center text=[#282b2f] font-semibold mt-4`,
}

const Home: NextPage = () => {
  const { address, connectWallet } = useWeb3()
  return (
    <div className={style.wrapper}>
      {address ? (
     <>
      <Header/>
     <Hero/>
     </>
     ) : (
       <div className={style.walletConnectWrapper}>
        <button
          className={style.button}
          onClick={() => connectWallet('injected')}
        > 
          Connect Wallet

        </button>
       </div>
     )}
   
    </div>
  
  )
}

export default Home

I am following a guide to building an NFT marketplace with Next.js. I am stuck on the part for building a button that should open metamask. As far as I understand 'connectWallet('injected')' should open metamask, but for me, nothing happens. Not even an error message. What could be the issue here?

import type { NextPage } from 'next'
import Header from '../components/Header'
import Hero from '../components/Hero'
import { useWeb3 } from '@3rdweb/hooks'

const style = {
  wrapper: ``,
  walletConnectWrapper: `flex flex-col justify-center items-center h-screen w-screen bg-[#3b3d42] `,
  button: `border border-[#282b2f] bg-[#2081e2] p-[0.8rem] text-xl font-semibold rounded-lg cursor-pointer text-black`,
  details: `text-lg text-center text=[#282b2f] font-semibold mt-4`,
}

const Home: NextPage = () => {
  const { address, connectWallet } = useWeb3()
  return (
    <div className={style.wrapper}>
      {address ? (
     <>
      <Header/>
     <Hero/>
     </>
     ) : (
       <div className={style.walletConnectWrapper}>
        <button
          className={style.button}
          onClick={() => connectWallet('injected')}
        > 
          Connect Wallet

        </button>
       </div>
     )}
   
    </div>
  
  )
}

export default Home

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终陌 2025-01-17 11:55:16

我认为您没有包装 _app.js。基于此文档

import { ThirdwebWeb3Provider } from '@3rdweb/hooks'


const supportedChainIds = [1,4,137]
const connectors = {
  injected: {},
}

function MyApp({ Component, pageProps }) {
  return (
    <ThirdwebWeb3Provider
      supportedChainIds={supportedChainIds}
      connectors={connectors}
    >
      <Component {...pageProps} />
    </ThirdwebWeb3Provider>
  )
}

I think you did not wrap the _app.js. Based on this docs

import { ThirdwebWeb3Provider } from '@3rdweb/hooks'


const supportedChainIds = [1,4,137]
const connectors = {
  injected: {},
}

function MyApp({ Component, pageProps }) {
  return (
    <ThirdwebWeb3Provider
      supportedChainIds={supportedChainIds}
      connectors={connectors}
    >
      <Component {...pageProps} />
    </ThirdwebWeb3Provider>
  )
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文