I used to have a before save function to fetch the metadata of NFT into the NFTOwners used to work perfectly until a recent update that broke it at some point the log said it was failing at the require https line says mod require is not defined. right now its having another error
Iâve tried to pull in the metadata through the web3api as follow but no errors and no luck either
var dataFromURI = await Moralis.Web3API.token.getTokenIdMetadata({ address: tokenAddress, token_id: tokenId, chain: âbsc testnetâ}).then((result) => {
return result;
});
any body can shed some light what am I doing wrong or how to go now about achieving same result again.
Moralis.Cloud.beforeSave(âBscNFTOwnersâ, async (request) => {
const tokenAddress = request.object.get(âtoken_addressâ);
const tokenId = request.object.get(âtoken_idâ);
const tokenUri = request.object.get(âtoken_uriâ);
if (!tokenUri) return;
var dataFromURI = await httpGet(tokenUri);
request.object.set(âmetadataâ, dataFromURI);
});
function httpGet(uri) {
const https = require(âhttpsâ);
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); });
});
}