首页 > 解决方案 > 如何从 Web3 中的 ETH 账户中获取令牌名称?

问题描述

我正在尝试使用 Web3 从 ETH 地址获取令牌名称(假设用户拥有ethada),但我在文档中找不到任何相关方法,我该怎么做?

我现在的代码:

     import Web3 from 'web3'

     try {
        const ethereum = (window as any).ethereum
        if (!ethereum) return

        await ethereum.enable()

        const web3 = new Web3(ethereum)


        //Got the address here, just getting the first one
        const account = (await web3.eth.getAccounts())[0]

        //Got the balance here
        const balance = await web3.eth.getBalance(account)

        //How can I get the token name related with that address?

      } catch (e) {

      }

标签: web3

解决方案


推荐阅读