Error saving on IPFS

In docs interface it works, if I use window.btoa(JSON.stringify(MYJSON))

In my code no, this is the abi I pass to Moralis function

[
  {
    path: 'metadata.json',
    content: 'eyJQbG90SUQiOiIweDUzNTk0MTU4NDNlMjcwOTBkOWFlZTU1NjU3MTNmYjE5ZDhiNGM3M2Y4M2E5YjBkMWNjY2M3ZjBkZDQ1OThhMWIiLCJQbG90WCI6IjExIiwiUGxvdFkiOiI0IiwiTG9jYXRpb25YIjoiMTEwMCIsIkxvY2F0aW9uWSI6IjQwMCIsImltYWdlSGFzaCI6IlFtTmpSY2l0OWNkOVBQU1pjZjhISkZqRVB1RVFkWGhjS0g2WFlZbmVnNHY1bmQiLCJpbWFnZUlwZnMiOiJodHRwczovL2lwZnMubW9yYWxpcy5pbzoyMDUzL2lwZnMvUW1OalJjaXQ5Y2Q5UFBTWmNmOEhKRmpFUHVFUWRYaGNLSDZYWVluZWc0djVuZC8weDUzNTk0MTU4NDNlMjcwOTBkOWFlZTU1NjU3MTNmYjE5ZDhiNGM3M2Y4M2E5YjBkMWNjY2M3ZjBkZDQ1OThhMWIucG5nIn0='
  }
]

Try with only a string maybe?
Can you add some logging to see what you send in that request?

Trying to send just a string (ā€œsā€) converted in base64, so window.btoa(ā€œsā€) in the content I get this error

{ā€œresā€:ā€œKOā€,ā€œmsgā€:{ā€œnameā€:ā€œMoralis SDK Errorā€,ā€œisMoralisErrorā€:true,ā€œcodeā€:ā€œC0005ā€}}

what part of this input you are trying to convert it to base64?

The content is a json like that some message above stringified and converted in base64
Something like this

const data = {
    path: 'metadata.json',
    content: {
      PlotID: '0xca060fe0631114c2392bbf43b75b10a3006b2562588b58cb8b4abb7b9895b9fd',
      PlotX: '5',
      PlotY: '7',
      LocationX: '500',
      LocationY: '700',
      imageHash: 'Qmar3TbD4SJCVomEHYADm8gjtmM4Zz2C9DJvRLhse9KQLH',
      imageIpfs: 'https://ipfs.moralis.io:2053/ipfs/Qmar3TbD4SJCVomEHYADm8gjtmM4Zz2C9DJvRLhse9KQLH/0xca060fe0631114c2392bbf43b75b10a3006b2562588b58cb8b4abb7b9895b9fd.png'
    }
  }

content: window.btoa(JSON.stringify(data))

The thing I canā€™t figure it out is that if I call my node function that call Moralis ipfs uploaf function with Insomnia (software like postman) it works, within my frontend javascript no

How you can see within the content thereā€™s an ipfs.moralis link so this function works, but somehow this call doesnā€™t work

it looks like this is the part that should e converted be string and than to base64

Yes, sorry, my previous message was wrong, I convert into string and then base64 that json you wrote above that is the content value

Can you share a complete code that doesnā€™t work?

Yes, this is the code
Frontend

//here I initialize the json and pass to a function
		const metadata = {
			"PlotID": plotID.toString(),
			"PlotX": land.tile.x.toString(),
			"PlotY": land.tile.y.toString(),
			"LocationX": land.absPosition.x.toString(),
			"LocationY": land.absPosition.y.toString(),
			"imageHash": land.imageHash.toString(),
			"imageIpfs": land.imageIpfs.toString()
		}

		const metadataFile = await savePlotDataToIPFS(metadata);


//function
async function savePlotDataToIPFS(metadata) {
	const params = {
		ppath: "metadata.json",
		pcontent: window.btoa(JSON.stringify(metadata))
	}

	const res = await handleApiPost('moralis/save-plot', params);

	if (res.res == "OK")
		return res.msg;
	else
		return null;
}


//function
const handleApiPost = async (endpoint, params) => {
	const result = await axios.post(`${serverUrl}/${endpoint}`, params, {
		headers: {
			'Content-Type': 'application/json',
		},
	});

	return result.data;
};

Here is my Backend

exports.savePlotToIPFS = async (req, res) => {

  //check the req body
  if (!req.body) {
    res.status(400).send({
      res: "KO",
      msg: "No data"
    });
    return;
  }
   const abi = [
     {
       path: req.body.ppath.toString(),
       content: req.body.pcontent.toString()
     },
   ];

  try {
    const response = await Moralis.EvmApi.ipfs.uploadFolder({
         abi
    });

    res.status(200).send({
      res: "OK",
      msg: {
        "ipfs": response.jsonResponse[0].path,
        "hash": response.jsonResponse[0].path.split('/')[4]
      }
    });

  } catch(err){
    res.status(400).send({
      res: "KO",
      msg: err
    });
  }
}

Thatā€™s all

Try to add some logging here to see that is the value for that abi

Here you may have to send the parameters as a string

Using JSON.stringify same errorā€¦

try to add some logging with console.log for the parameters

Now I get error in authentication function Moralis.Auth.requestMessage

this is the payload

{
    "address": "0x4e6b9ae717c34d8f0047f1c40e6459fa6b25d381",
    "chain": "0x1",
    "network": "evm",
    "DOMAIN": "dc3.space",
    "STATEMENT": "Please sign this message to confirm your identity.",
    "URI": "https://dc3.space/dc3land",
    "EXPIRATION_TIME": "2024-01-01T00:00:00.000Z",
    "TIMEOUT": 30
}

and this is the issue

{
ā€œresā€: ā€œKOā€,
ā€œmsgā€: {
ā€œnameā€: ā€œMoralis SDK Errorā€,
ā€œisMoralisErrorā€: true,
ā€œcodeā€: ā€œC0005ā€
}
}

Iā€™ve updated Moralis version to 2.18.0

Is there something wrong with your SDK?

the same syntax worked before?

there keys have to be in uppercase?

This is the payload to my node function that calls Moralis.Auth.requestMessage

const result = await Moralis.Auth.requestMessage({
      address: paddress,
      chain,
      network,
      domain: req.body.DOMAIN,
      statement: req.body.STATEMENT,
      uri: req.body.URI,
      expirationTime: req.body.EXPIRATION_TIME,
      timeout: req.body.TIMEOUT,
    });

Yes, same syntax worked before

I used this code now and I didnā€™t get any error:

Moralis = require("moralis").default

r = async () => {
  await Moralis.start({
    apiKey: "API_KEY_HERE"
  });


  const result = await Moralis.Auth.requestMessage({
      address: "0x347a96a5bd06d2e15199b032f46fb724d6c73047",
      chain: "0x1",
      network: "evm",
      domain: "google.com",
      statement: "google",
      uri: "https://google.com",
      expirationTime: "2024-01-01T00:00:00.000Z",
      timeout: 55,
    });

  console.log(result);
}

r()

I used "version": "2.16.1", for Moralis SDK

in the latest version of the sdk you have to comment this line:

as in this works:

  const result = await Moralis.Auth.requestMessage({
      address: "0x347a96a5bd06d2e15199b032f46fb724d6c73047",
      chain: "0x1",
      //network: "evm",
      domain: "google.com",
      statement: "google",
      uri: "https://google.com",
      expirationTime: "2024-01-01T00:00:00.000Z",
      timeout: 55,
    });

This is my error if I comment network line as you suggested with Moralis 2.18.1

MoralisError [Moralis SDK Core Error]: [C0005] Invalid address provided
at Function.EvmAddress.parse (C:\PROGETTI\PERSONALI\DC3Land\Api\node_modules@moralisweb3\common-evm-utils\lib\cjs\index.cjs:107:19)
at new EvmAddress (C:\PROGETTI\PERSONALI\DC3Land\Api\node_modules@moralisweb3\common-evm-utils\lib\cjs\index.cjs:75:34)
at Function.EvmAddress.create (C:\PROGETTI\PERSONALI\DC3Land\Api\node_modules@moralisweb3\common-evm-utils\lib\cjs\index.cjs:103:16)
at makeEvmRequestMessage (C:\PROGETTI\PERSONALI\DC3Land\Api\node_modules@moralisweb3\auth\lib\cjs\index.cjs:113:209)
at C:\PROGETTI\PERSONALI\DC3Land\Api\node_modules@moralisweb3\auth\lib\cjs\index.cjs:138:43
at step (C:\PROGETTI\PERSONALI\DC3Land\Api\node_modules@moralisweb3\auth\lib\cjs\index.cjs:98:23)
at Object.next (C:\PROGETTI\PERSONALI\DC3Land\Api\node_modules@moralisweb3\auth\lib\cjs\index.cjs:79:53)
at C:\PROGETTI\PERSONALI\DC3Land\Api\node_modules@moralisweb3\auth\lib\cjs\index.cjs:72:71
at new Promise ()
at __awaiter (C:\PROGETTI\PERSONALI\DC3Land\Api\node_modules@moralisweb3\auth\lib\cjs\index.cjs:68:12)
at C:\PROGETTI\PERSONALI\DC3Land\Api\node_modules@moralisweb3\auth\lib\cjs\index.cjs:127:79
at Auth._this.requestMessage (C:\PROGETTI\PERSONALI\DC3Land\Api\node_modules@moralisweb3\auth\lib\cjs\index.cjs:233:90)
at exports.request (C:\PROGETTI\PERSONALI\DC3Land\Api\moralis\moralis.controller.js:30:39)
at Layer.handle [as handle_request] (C:\PROGETTI\PERSONALI\DC3Land\Api\node_modules\express\lib\router\layer.js:95:5)
at next (C:\PROGETTI\PERSONALI\DC3Land\Api\node_modules\express\lib\router\route.js:144:13)
at Route.dispatch (C:\PROGETTI\PERSONALI\DC3Land\Api\node_modules\express\lib\router\route.js:114:3) {
isMoralisError: true,
code: ā€˜C0005ā€™,
details: undefined,
[cause]: undefined
}

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.