你好,我正在尝试使用一个基于 Solidity 的合约,并使用 React 和 TypeScript 在我的前端与 Brownie 一起部署。还使用框架usedapp,正如这里的文档所说,为了与合约函数交互,我应该创建一个新合约,提供地址和ABI。这是我的代码:
import {useContractFunction, useEthers} from '@usedapp/core'
import TokenFarm from "../chain-info/contracts/TokenFarm.json"
import ERC20 from "../chain-info/contracts/MockERC20.json"
import networkMapping from "../chain-info/deployments/map.json"
import {constants, utils} from "ethers"
import {Contract} from '@ethersproject/contracts'
export const useStakeTokens = (tokenAddress: string) => {
// chainId
const {chainId} = useEthers()
// abi
const {abi} = TokenFarm
// address
// const dappTokenAddress = chainId ? networkMapping[String(chainId)]["DappToken"][0] : constants.AddressZero
const tokenFarmAddress = chainId ? networkMapping[String(chainId)]["TokenFarm"][0] : constants.AddressZero
// approve
const tokenFarmInterface …Run Code Online (Sandbox Code Playgroud)