I’m trying to mintNFT using mintNFT function.
Contract is right and I’ve followed rarible clone video on YT.
Error:
Error in metamask
Warnings in the console:
Code:
import React, {useState,useEffect} from 'react'
import { useMoralis, useMoralisFile,useNewMoralisObject} from 'react-moralis';
import '../Create.css';
import {tokenContractAbi} from '../abi.js';
const TOKEN_CONTRACT_ADDRESS="*********************************************";
function Createcomponent() {
//initialisations
const{Moralis,enableWeb3, isWeb3Enabled, web3,isAuthenticated}=useMoralis();
const { save } = useNewMoralisObject('Item');
const {saveFile} = useMoralisFile();
const [file, setFile] = useState('');
const [filename, setFilename] = useState("");
const [price, setPrice] = useState("0");
const [nftstatus, setNftstatus] = useState("Not For Sale");
const [description, setDescription] = useState("");
// const web3 = await Moralis.Web3.enable();
const tokenContract = new web3.eth.Contract(tokenContractAbi, TOKEN_CONTRACT_ADDRESS);
useEffect(() => {
if (isAuthenticated) {
enableWeb3();
}
}, [isAuthenticated]);
// This function is triggered when NFT file is selected
const onFileChange = (event) => {
if (event.target.files && event.target.files[0]) {
setFile(event.target.files[0]);
}
}
console.log(isWeb3Enabled);
//This functions is triggered when create NFT button is pressed
const onCreateItem = async (e) => {
e.preventDefault();
//console.log(file);
const fileIpfs= await saveFile("nftFile.png",file,{
saveIPFS:true
});
//console.log(fileIpfs);
const nftFilePath = fileIpfs._ipfs;
const nftFileHash=fileIpfs._hash;
//console.log(nftFileHash,nftFilePath);
const metadata = {
name: filename,
description: description,
image: nftFilePath,
};
const metadataFileIpfs= await saveFile("metadata.json", {base64 : btoa(JSON.stringify(metadata))},{
saveIPFS:true
});
//console.log(metadataFileIpfs);
const nftFileMetaDataPath = metadataFileIpfs._ipfs;
const nftFileMetaDataHash = metadataFileIpfs._hash;
//console.log(nftFileMetaDataHash,nftFileMetaDataPath);
const mintNft = async (metadataUrl) => {
const receipt = await tokenContract.methods.createItem(metadataUrl).send({from: ethereum.selectedAddress });
:**Here I get ethereum not found error, when I put my wallet address and run I get the error mentioned above**
console.log(receipt);
return receipt.events.Transfer.returnValues.tokenId;
};
const nftId = await mintNft(nftFileMetaDataPath);
await save({
'name':filename,
'description':description,
'nftFilePath':nftFilePath,
'nftFileHash':nftFileHash,
'nftFileMetaDataPath':nftFileMetaDataPath,
'nftFileMetaDataHash':nftFileMetaDataHash,
'nftId':nftId,
'nftContractAddress':TOKEN_CONTRACT_ADDRESS,
});