Hi,
Iām doing a NFT market place similar to Rarible. Iām following the tutorial to clone Rarible but I have a problem minting the NFTs. IPFS upload is fine but the minting is getting the follow issue:
Proxy is connected, Ganache es on, double checked the solidity code and the abi, everything is the same as the tutorial.
This is the JS:
const serverUrl = "https://myl2ry6v1k2v.usemoralis.com:2053/server";
const appId = "VqIso7CcbXtvDOaEjAdB1RjpWQrMmbin9k3MEAnq";
const TOKEN_CONTRACT_ADDRESS = "0xE3A3CB628206aD4554306badaDEef1657F627197";
Moralis.start({ serverUrl, appId });
let createNewNFT = document.getElementById("fileNewNFT");
let nameNewNFT = document.getElementById("txtItemName");
let descriptionNFT = document.getElementById("txtItemDescription");
createItem = async () => {
if (createNewNFT.files.lenght == 0) {
console.log("Select a file");
return
} else if (nameNewNFT.value.length == 0) {
console.log("Give the NFT a name");
return;
}
const nftFile = new Moralis.File("nftFile.jpg", createNewNFT.files[0]);
await nftFile.saveIPFS();
const nftFilePath = nftFile.ipfs();
const nftFileHash = nftFile.hash();
const metadata = {
name: nameNewNFT.value,
description: descriptionNFT.value,
image: nftFilePath,
};
const metadataNFT = new Moralis.File("metadata.json", { base64: btoa(JSON.stringify(metadata)) });
await metadataNFT.saveIPFS();
const nftFileMetadataFile = metadataNFT.ipfs();
console.log(nftFileMetadataFile);
const nftId = await mintNFT(nftFileMetadataFile);
const Item = Moralis.Object.extend("Item");
const item = new Item();
item.set('name', nameNewNFT.value);
item.set('description', descriptionNFT.value);
item.set('nftFilePath', nftFilePath);
item.set('nftFileHash', nftFileHash);
item.set('metaFilePath', metadataNFT.ipfs());
item.set('metaFileHash', metadataNFT.hash());
item.set('nftId', nftId);
item.set('nftContractAddress', TOKEN_CONTRACT_ADDRESS);
await item.save();
console.log(item);
}
function loggedOut() {
console.log("no esta logueado");
window.open("../index.html", "_self");
}
function fadeOut() {
user = Moralis.User.current();
}
mintNFT = async (metadataURL) => {
const receipt = await tokenContract.methods.createItem(metadataURL).send({from: ethereum.selectedAddress});
console.log(receipt);
return receipt.event.Transfer.returnValues.tokenId;
}
function clickUploadNDF(){
document.getElementById("fileNewNFT").click();
}
iniciar = async () => {
const ethers = Moralis.web3Library;
window.web3 = await Moralis.enableWeb3();
window.tokenContract = new ethers.Contract(TOKEN_CONTRACT_ADDRESS, tokenContractAbi);
if (await Moralis.User.current()) {
fadeOut();
} else { loggedOut(); }
}
window.onload = iniciar;
document.getElementById("add-photo").onclick = clickUploadNDF;