使用 React 连接到元掩码,Next.js 不起作用
我正在遵循使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您没有包装
_app.js
。基于此文档I think you did not wrap the
_app.js
. Based on this docs