Walletbalance.tsx代币余额回报:未定义
我已经完成了全栈 defi 课程,当我使用usedapp/core 中的 useTokenBalance 函数时,我没有返回任何内容,我不知道我哪里出了问题,因为当我 console.log 地址时以及它返回的帐户变量以及正确的帐户地址和正确的令牌地址。
这是这里的打字稿:
import {useEthers, useTokenBalance} from "@usedapp/core"
import {formatUnits} from "@ethersproject/units"
export interface WalletBalanceProps {
token: Token
}
export const WalletBalance = ({token}: WalletBalanceProps) => {
const {image, address, name} = token
const {account} = useEthers()
console.log(account)
console.log(address)
const tokenBalance = useTokenBalance(address, account)
const formattedTokenBalance: number = tokenBalance ? parseFloat(formatUnits(tokenBalance, 18)) : 0
console.log(tokenBalance?.toString())
return (<div>{formattedTokenBalance}</div>)
}
我认为这可能是 @usedapp/core 的错误,但我重新安装了 @usedapp/core ,但仍然返回相同的错误。任何帮助都会有用的:)
I've been completing the full-stack-defi course and when I use the useTokenBalance function from usedapp/core I get returned nothing, I don't know where I've went wrong because I've when I console.log the address and the account variables it returns with the correct account address and the correct token address.
Here's the typescript here:
import {useEthers, useTokenBalance} from "@usedapp/core"
import {formatUnits} from "@ethersproject/units"
export interface WalletBalanceProps {
token: Token
}
export const WalletBalance = ({token}: WalletBalanceProps) => {
const {image, address, name} = token
const {account} = useEthers()
console.log(account)
console.log(address)
const tokenBalance = useTokenBalance(address, account)
const formattedTokenBalance: number = tokenBalance ? parseFloat(formatUnits(tokenBalance, 18)) : 0
console.log(tokenBalance?.toString())
return (<div>{formattedTokenBalance}</div>)
}
I thought this could be an error with @usedapp/core but I reinstalled @usedapp/core and I'm still getting the same error returned. Any help would be useful :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该尝试更改 App.tsx 中的配置设置
You should try to change the config settings in App.tsx
我有同样的问题。 Console.Log返回正确的令牌和帐户地址,USEtokenBalance()返回未定义。
i have exactly the same problem. console.log returns correct token and account addresses, useTokenBalance() returns undefined.