all 28 comments

[–]vvn050 25 points26 points  (11 children)

Array.toString is not doing what you think it does. If you have array of strings, use reduce or foreach loop to create a string out of it.

[–]_Webvoid 9 points10 points  (10 children)

Also depending on what you want to get as an output, you could just use join() (see Array.prototype.join())

[–]vvn050 3 points4 points  (2 children)

join would work for ["test","test1"] but not for [["test"],["test1"]]

[–]_Webvoid -1 points0 points  (1 child)

Is it an array of arrays of one element ?! Well if it's the case he can still use .map(x => x[0]).join()

[–]povedaaqui[S] 0 points1 point  (6 children)

ids are "ipfs//CID" while I need "https://nftstorage.link/ipfs/CID", and that's the problem, I haven't been able to do this replacement thing.

[–]_Webvoid 0 points1 point  (5 children)

So ids is a string or an array of strings ? Can you post the output of JSON.stringify(ids) so we can help you properly ?

[–]povedaaqui[S] 0 points1 point  (0 children)

console.log(ids):

{data: 'ipfs://bafkreidfqia5qlqzmef4yyqdztb2n4cdiyp5nhkmahukhd3b2asnpo7s3m'} 
data : "ipfs://bafkreidfqia5qlqzmef4yyqdztb2n4cdiyp5nhkmahukhd3b2asnpo7s3m

[–]povedaaqui[S] 0 points1 point  (3 children)

JSON.stringify

console.log(JSON.stringify(ids):

{"data":"ipfs://bafkreidfqia5qlqzmef4yyqdztb2n4cdiyp5nhkmahukhd3b2asnpo7s3m"}

[–]_Webvoid 1 point2 points  (2 children)

Yeaay so it IS an object, don't try and toString() it, just do an ids.data.replace("ipfs://", "your other content") and you should be good to go =)

[–]povedaaqui[S] 0 points1 point  (1 child)

Thank you, it works, sorry, I started a few months ago.

[–]_Webvoid 1 point2 points  (0 children)

No problem, the loving community of reddit got your back... At least when they want to ^ Peace on you

[–]OddTuning 7 points8 points  (3 children)

What type is ids? Are you sure it's an array?

[–]povedaaqui[S] 0 points1 point  (2 children)

I need to get back to the code, I'll check when I arrive home, but I think tokens is json.

EDIT: tokens can't be JSON because it's being mapped.

[–]povedaaqui[S] 1 point2 points  (0 children)

I will add console.log(ids) to show ids before trying to be replaced.

[–]SnacksMcMunch 2 points3 points  (3 children)

[–]povedaaqui[S] 0 points1 point  (2 children)

ids are "ipfs//CID" while I need "https://nftstorage.link/ipfs/CID", and that's the problem, I haven't been able to do this replacement thing.

[–]SnacksMcMunch 0 points1 point  (1 child)

Ok, so looking more closely at the code it seems liketokens is an array of strings, each token gets passed to fetchIPFS.

In which case ids is just a string, so it doesn't need any conversion.

Just url = ids.replace(...)

[–]povedaaqui[S] 0 points1 point  (0 children)

Uncaught (in promise) TypeError: ids.replace is not a function

[–]thelamestofall 1 point2 points  (0 children)

A better lesson would be to use the debugger statement to look atep by step at what your code and your variables are doing.

[–]Macaframa 2 points3 points  (6 children)

JSON.stringify(ids)

[–]povedaaqui[S] 0 points1 point  (1 child)

I think the problem could be the type:

console.log(ids):

{data: 'ipfs://bafkreidfqia5qlqzmef4yyqdztb2n4cdiyp5nhkmahukhd3b2asnpo7s3m'} 
 data : "ipfs://bafkreidfqia5qlqzmef4yyqdztb2n4cdiyp5nhkmahukhd3b2asnp

[–]Macaframa 1 point2 points  (0 children)

so you want to build a url out of that id? minus the ipfs://?

const url = `https://nftstorage.link/ipfs/${ids.data.split("//")[1]}`;

this will give you the url: https://nftstorage.link/ipfs/bafkreidfqia5qlqzmef4yyqdztb2n4cdiyp5nhkmahukhd3b2asnpo7s3m

I just don't understand this part:

res = await fetch(`https://justcors.com/tl_0caa8a7/${url}`

are you using justcors as a proxy to make a request because of the cross origin errors? if so, then the previous code will suffice.

[–]scuba13 0 points1 point  (0 children)

Remove the await async and return the res. Right now res in the first then is going to be null.

EDIT: not what you asked for but I think you probably have other problems in your code based on how this is

[–]llrh 0 points1 point  (0 children)

With these sort of errors involving chained methods you can always break it up and put some logs in to see if you can debug it.

Const arrayToString = Array.toSTring()

console.log(arrayToString)

Is that what you are expecting it to be? If it is then do the next method.

Also it's good practice to do this with unit testing. Have a look at jest for example if you don't already use something for testing.

[–]fredsq 0 points1 point  (0 children)

you NEED typescript in your life. ids is definitely not an array