Where to get token contract addresses?

I am following the Moralis tutorial to clone OpenSea. I am wondering how they got the addresses for the token contracts used in the tutorial. When I look on EtherScan, and try for example https://etherscan.io/token/0x8943c7bac1914c9a7aba750bf2b6b09fd21037e0 when I run that address for the contract through the Moralis Moralis.Web3API.token.getAllTokenIds I get an error and no Json.

This seems to work fine with the contract. Maybe the error is caused by some other line.
image

Thank you for the help. Yes, it works fine with the contract but I really want the image url from the metadata so that is where there is an error happening. I tried taking it out of the try/catch block and then rewriting the code and not I am getting “TypeError: image.startsWith is not a function” Any idea what is happening? Were you able to parse the metadata and get it to send the json back?

router.get('/usernfts', async (req, res) => {
  const options = {
    chain: 'eth',
    address: '0x8a08e3Ce6CED24d376a13C544E45d4DDa02FaFEA',
  }
  await Moralis.start({ serverUrl, appId })
  const userNFTsRes = await Moralis.Web3API.account.getNFTs(options)
  let userNFTs = userNFTsRes.result
  for (const item of userNFTs) {
    if (item.metadata) {
      let metadata = JSON.parse(item['metadata'])
      let image = metadata['image'] ? metadata['image'] : false
      if (image.startsWith('ipfs')) {
        image_url = image.replace('ipfs://', '')
        formated_url = `https://ipfs.io/ipfs/${image_url}`
        item.image = formated_url
      } else {
        item.image = image
      }
    }
  }
  res.json(userNFTs)
})

I am not able to recreate the same error from you code. It is working as expected.

Can you check this if you can find some related answer here.

THANK YOU SO MUCH! It was as simple as calling .toString() before starts with :smile:

1 Like