issue-tracker
issue-tracker copied to clipboard
Automatically pull NFT metadata into the NFTTokenOwners table
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));
});