issue-tracker icon indicating copy to clipboard operation
issue-tracker copied to clipboard

Automatically pull NFT metadata into the NFTTokenOwners table

Open Capplequoppe opened this issue 3 years ago • 0 comments

The following code could be put as a core part of moralis to automatically pull in metadata info when syncing to the NFTTokenOwners table. This would save the client a bunch of calls when trying to get the metadata.

function httpGet(uri) {
  return new Promise ((resolve, reject) => {
    https.get(uri, (response) => {
      let data = '';
      response.on('data', (chunk) => { data += chunk; });
      response.on('end', () => { resolve(data); });
    }).on("error", (error) => { reject(error); });
  }); 
}
Moralis.Cloud.beforeSave("NFTTokenOwners", async (request) => {
  const tokenUri = request.object.get('token_uri');
  if (!tokenUri) return;
  request.object.set("metadata", await httpGet(tokenUri));
});   

Capplequoppe avatar Apr 12 '21 17:04 Capplequoppe