-
Hello there I'm getting a weird error trying to execute 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 = new utils.Interface(abi)
const tokenFarmContract = new Contract(tokenFarmAddress, tokenFarmInterface)
const erc20ABI = ERC20.abi
const erc20Interface = new utils.Interface(erc20ABI)
const erc20Contract = new Contract(tokenAddress, erc20Interface)
// approve
const { send: approveErc20Send, state: approveAndStakeErc20State } =
useContractFunction(erc20Contract, "approve", {
transactionName: "Approve ERC20 transfer",
})
} The error occurs on This is the complete error message
Argument of type 'import("/home/cromewar/Solidity-Projects/full_defi_app/dev/front_end/node_modules/@ethersproject/contracts/lib/index").Contract' is not assignable to parameter of type 'import("/home/cromewar/Solidity-Projects/full_defi_app/dev/front_end/node_modules/@usedapp/core/node_modules/@ethersproject/contracts/lib/index").Contract'. It says the types are not compatible but they are actually the exact same, does anyone has a clue about what is happening? I also cloned the code from the repo but the error stills, @PatrickAlphaC have you any clue why this is happening? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Solution: Patrick had the exact same problem on this video for chainlink's hackathon, seeing the video I noticed the problem vscode was mainly complaining about two instances of It seems Replace this line:
For this line:
and eureka, the problem is solved ;) Thanks @PatrickAlphaC if it wasn't for the video I would never have noticed the error. |
Beta Was this translation helpful? Give feedback.
Solution:
Patrick had the exact same problem on this video for chainlink's hackathon, seeing the video I noticed the problem vscode was mainly complaining about two instances of
node_modules
between @usedapp and @ethersproject/contracts.It seems
@usedapp
already comes with a implementation ofethersproject
inside of it, so I found the solution.Replace this line:
import {Contract} from '@ethersproject/contracts'
For this line:
import {Contract} from '@usedapp/core/node_modules/@ethersproject/contracts'
and eureka, the problem is solved ;)
Thanks @PatrickAlphaC if it wasn't for the video I would never have noticed the error.