Cannot read properties of undefined (reading tokenaddress)

Whenever I run the script to upload an NFT to Rarible, I get an error message saying:

  1. details: {method: ‘lazyMint’, payload: {…}, error: ‘Request failed with status code 400’}
  2. message: “Cannot lazy mint the token”

and an error saying:

ncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘tokenAddress’)
at HTMLButtonElement.submit (main.js:58:83)

I tried changing my speedy nodes to ws on the rarible api and I updated it, but no luck so far.

Here is my code:

async function submit(){
const input = document.querySelector(’#input_image’);
let data = input.files[0]
const imageFile = new Moralis.File(data.name, data)
await imageFile.saveIPFS();
let imageHash = imageFile.hash();

let metadata = {
    name: document.querySelector('#input_name').value,
    description: document.querySelector('#input_description').value,
    image: "/ipfs/" + imageHash
}
console.log(metadata);
const jsonFile = new Moralis.File("metadata.json", {base64 : btoa(JSON.stringify(metadata))});
await jsonFile.saveIPFS();

let metadataHash = jsonFile.hash();
console.log(jsonFile.ipfs())
let res = await Moralis.Plugins.rarible.lazyMint({
  chain: 'eth',
  userAddress: user.get('ethAddress'),
  tokenType: 'ERC721',
  tokenUri: 'ipfs://' + metadataHash,
  supply: 1,
  royaltiesAmount: 5, // 0.05% royalty. Optional
})

console.log(res);
document.querySelector('#success_message').innerHTML = 
    `NFT minted. <a href="https://rinkeby.rarible.com/token/${res.data.result.tokenAddress}:${res.data.result.tokenId}">View NFT`;
document.querySelector('#success_message').style.display = "block";
setTimeout(() => {
    document.querySelector('#success_message').style.display = "none";
}, 5000)

}

login();

Looks like it might be because res.data is undefined and you’re trying to take tokenAddress out of the `undefined there :raised_hands: