Chapter 8: (HTML Javascript Fund Me) | Property 'Fund' does not exist on type 'Contract' [TypeScript] #644
-
I am using
const transactionResp = await contract.Fund({ value: ethers.utils.parseEther(ethAmount) }); Error that I get error TS2339: Property 'Fund' does not exist on type 'Contract'. My export const contractAddress = "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512";
export const abi = [
{
inputs: [
{
internalType: "address",
name: "PriceFeed",
type: "address",
},
],
stateMutability: "nonpayable",
type: "constructor",
},
{
inputs: [],
name: "FundMe__NotOwner",
type: "error",
},
{
stateMutability: "payable",
type: "fallback",
},
{
inputs: [],
name: "Fund",
outputs: [],
stateMutability: "payable",
type: "function",
},
{
inputs: [],
name: "MINIMUM_USD",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "cheaperWithdraw",
outputs: [],
stateMutability: "payable",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "funder",
type: "address",
},
],
name: "getAddressToAmountFunded",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [
{
internalType: "uint256",
name: "index",
type: "uint256",
},
],
name: "getFunders",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "getOwner",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "getPriceFeed",
outputs: [
{
internalType: "contract AggregatorV3Interface",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "withdraw",
outputs: [],
stateMutability: "payable",
type: "function",
},
{
stateMutability: "payable",
type: "receive",
},
]; The full code of import { ethers } from "./lib/ethers-5.2.esm.min.js";
import { contractAddress, abi } from "./lib/constants.js";
const connectBtn: HTMLButtonElement = document.getElementById("connectButton") as HTMLButtonElement;
const fundBtn: HTMLButtonElement = document.getElementById("fundButton") as HTMLButtonElement;
connectBtn.onclick = connect;
fundBtn.onclick = fund;
async function connect() {
if (typeof window.ethereum !== "undefined") {
try {
await window.ethereum.request({ method: "eth_requestAccounts" });
} catch (e) {
console.log(e);
}
connectBtn.innerHTML = "Connected";
} else {
connectBtn.innerHTML = "Install Metamask";
}
}
async function fund() {
const amount = "0.2";
if (typeof window.ethereum !== "undefined") {
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const contract = new ethers.Contract(contractAddress, abi, signer);
try {
const transactionResp = await contract.Fund({ value: ethers.utils.parseEther(amount) }); //Error line [error TS2339: Property 'Fund' does not exist on type 'Contract'.]
} catch (e) {
console.log(e);
}
//console.log(signer);
} else {
connectBtn.innerHTML = "Install Metamask";
}
} To me it look like its type casting error and hence typescript is not able to read it |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You'd need to use typechain if you want to use it like this: https://github.com/dethcrypto/TypeChain (I didn't do a typescript edition of the UI stuff... to be honest, it's probably easier to do this section in javascript and then just use typescript when you get to nextjs, but up to you) |
Beta Was this translation helpful? Give feedback.
You'd need to use typechain if you want to use it like this: https://github.com/dethcrypto/TypeChain
(I didn't do a typescript edition of the UI stuff... to be honest, it's probably easier to do this section in javascript and then just use typescript when you get to nextjs, but up to you)