首页 > 解决方案 > 如何解决 TypeError: Cannot read property 'then' of undefined

问题描述

我似乎无法让我的浏览器正确地使用 Fortmatic 进行身份验证并不断收到 TypeError: Cannot read property 'then' of undefined (我正在使用 nextjs)。

我已经放了一个按钮,以便我可以测试。一直试图弄清楚这一点。谢谢大家

import Head from 'next/head'
import styles from '../styles/Home.module.css'
import Githubcorner from './components/Githubcorner'
import React from 'react'
import Fortmatic from 'fortmatic'
import Web3 from 'web3'


export default function Home() {

  React.useEffect(() => {
    const fm = new Fortmatic('API_Key');
    window.web3 = new Web3(fm.getProvider());
    console.log("window.innerHeight", window.innerHeight);
  }, []);

  const handleGetAccounts = () => {
    web3.eth.getAccounts().then(console.log);
  }
  
  return (
    <div className={styles.container}>
      <Head>
        <title>Monaliza</title>
        <link rel="icon" href="/favicon.ico" />
      </Head>

      <main className={styles.main}>
        <button
        onClick={handleGetAccounts}>Random check</button>

        <div className={styles.grid}>
          <a
            href="/Instafeedpage"
            className={styles.card}
          >
            <h3>NFTs on The Gram &rarr;</h3>
            <p>See some dope minted NFTs on the gram</p>
          </a>
          <a
            href="/Instadroppage"
            className={styles.card}
          >
            <h3>Drop them NFTs &rarr;</h3>
            <p>Mint your own NFTs</p>
          </a>
        </div>
      </main>

      <footer className={styles.footer}>
      <a href={"https://github.com"}><img src="/githublogo.png" alt="Github Icon" className={styles.logo} /></a>
      <a href={"https://discord.com"}><img src="/discord.svg" alt="Discord Icon" className={styles.logo} /></a>
      </footer>
    </div>
  )
}

标签: node.jsnext.js

解决方案


推荐阅读