saveIPFS() function is not working as expected

first you upload the image to IPFS, you keep the link for the image, then you create a json file/object that contains that image link

you can upload from cloud code an image too, you already know how to do it in front end

you can also upload a json from front end, you’ll have to convert it to a string, you’ll find examples with btoa in other similar forum posts

I cannot use Moralis.Cloud.toIpfs() function. It says it’s not a function.

you may be able to use that only from cloud code

but I want to do this in the frontend side.

there is possible to do it in front end too, you can also call a cloud function in front end

what I am trying to do is just create an NFT in the frontend side using moralis and there is not clear instruction or example code in moralis documentation.

again. we don’t have any cloud function

you have to save a json file and an image to ipfs, it looks like you already managed to do one of them

yes, I was able to save image and get link to the image

const file = new Moralis.File(media[0].name, media[0])
      const res = await file.saveIPFS()

res.ipfs() returns the link to the image but what I am expecting to see is a json object which includes name, description and image because normal NFTs which I created from other platforms look like that.
we are paying paying moralis and use moralis on production but they didn’t reply me at all on github.

you have to create that json separately, something like:

metadata = {"info": "info"}
const jsonFile = new.Moralis.File("metadata.json", {base64: btoa(JSON.stringify(metadata))});
res2 = await file.saveIPFS()

Thanks @cryptokid. I was able to save and get json object and I used the response to deploy. It seems it’s showing up on opensea.io but now it’s not showing up on our app. we are using Moralis to fetch all NFTs from connected wallet. what could be the reason?

you can try to run getTokenIdMetadata for that token that you minted, it should index the contract in case that it was not already indexed

  const { data: nfts } = useNFTBalances()

I am using useNFTBalances hook to grab all NFTs. where should I should getTokenIdMetadata?

you can use it directly in admin interface in web3api tab, only until it will return some data to be sure that the contract is indexed by Moralis

I am not sure where getTokenIdMetadata is in web3api admin interface but what I want to do is

  1. Input name, description and select file from our app
  2. User clicks Mint button on our app
  3. Upload image to ipfs and deploy smart contract
  4. Show all created NFTs in a connected wallet on dashboard page

And I am using Moralis in all around the project. what should I do? if I should do something on admin interface to fetch NFTs then it’s not something I want to do.

what you mean by deploy smart contract?

const jsonFile = new Moralis.File('file.json', { base64: btoa(JSON.stringify(object)) })
      const res = await jsonFile.saveIPFS()

      const provider = new web3.providers.Web3Provider(window.ethereum)
      const factory = new web3.ContractFactory(ERC721.abi, ERC721.bytecode, provider.getSigner())
      const contract = await factory.deploy(name, description, res.ipfs())

      await contract.deployed()

why do you want to deploy a smart contract for every NFT?

sorry what do you mean by that? we want to make users be able to create and mint NFTs using our platform.