async function uploadArtToIPFS() {
try {
await nft.saveIPFS();
console.log(nft);
let nftPath = nft.ipfs();
console.log(nftPath);
uploadMetaDataToIPFS(nftPath);
} catch (err) {
console.log(err);
alert("Error saving art to ipfs");
$('#saveToIPFSBtn').prop('disabled', false);
$('#saveToIPFSBtn').html("Upload and Mint");
}
};
async function uploadMetaDataToIPFS(nftPath) {
$(β#saveToIPFSBtnβ).html(`Uploading metadata to IPFS
<span class="sr-only">Loading...</span>
</div>`);
try {
let allEmojiRegEx = /\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]/g;
const metadata = {
name: $('#title').val().replace(allEmojiRegEx, ''),
description: $('#descriptionInput').val().replace(allEmojiRegEx, ''),
image: nftPath
}
console.log(metadata);
const nftMetadata = new Moralis.File("nft-metadata.json", { base64: btoa(JSON.stringify(metadata)) });
console.log(nftMetadata);
await nftMetadata.saveIPFS();
console.log(nftMetadata);
let nftMetadataPath = nftMetadata.ipfs();
console.log(nftMetadataPath);
mint(nftMetadataPath, nftPath);
} catch (err) {
console.log(err);
alert("Error saving metadata to ipfs");
$('#saveToIPFSBtn').prop('disabled', false);
$('#saveToIPFSBtn').html("Upload and Mint");
}
};