If you copy exactly my code you get that error? Other functions work well?
yes
2021-10-18T18:32:18.462Z - Error: Invalid function: âget_token_uriâ
at handleCloudFunction (/moralis-server/lib/Routers/FunctionsRouter.js:119:13)
at /moralis-server/lib/PromiseRouter.js:85:20
at processTicksAndRejections (internal/process/task_queues.js:95:5)
Strange, are you sure you are connected to the right Moralis server? You get same error if you put there a random function name?
yes sure itâs the correct server Iâm just initiating and running from console at this point
this does work anyway so I might just change my before save to include it.
Moralis.Cloud.define(âtestMetadataâ, async (request) => {
const { chain, tokenAddress, tokenId, } = request.params;
return await Moralis.Web3API.token.getTokenIdMetadata({ address: tokenAddress, token_id: tokenId, chain: chain}).then((result) => {
return result;
});
});
well now trying to incorportate the very same code into the before save results in
- 2021-10-18T21:08:30.535Z - beforeSave failed for BscNFTOwners for user undefined: Input:
{ânameâ:âBlockchain Factoryâ,âsymbolâ:âBLCKCHNâ,âtoken_uriâ:âhttps://ipfs.moralis.io:2053/ipfs/QmWantQC68Re6vWpn1PktgtGJoe1mPEJ71yvNdatys1j1K",âtoken_idâ:â124â,âtoken_addressâ:â0x668aed884e1ebfa5dab26fc80ab0f8ecea59aa2bâ,âowner_ofâ:â0x4771ff1f558b3cc9996ec030fca95fd672425ef6â,âblock_numberâ:13343001,âamountâ:â1â,âcontract_typeâ:"ERC721â} Error: {âmessageâ:"[object Object]",âcodeâ:141}
here is the beforeSave()
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);
var dataFromURI = await Moralis.Web3API.token.getTokenIdMetadata({ address: tokenAddress, token_id: tokenId, chain: âbsc testnetâ}).then((result) => {
return result.metadata;
});
request.object.set("metadata", dataFromURI);
});
you could add some lines with logger.info(JSON.stringify(variable_name));
to see how far it gets in execution
even with ur code itâs not returning anything useful here is a sample
- 2021-10-18T21:31:49.200Z -
- 2021-10-18T21:31:49.200Z -
- 2021-10-18T21:31:49.200Z - error
the result could also depend on the url that it tries to access, sometimes that url could not work
except that all and every URL which is just files on the server itself btw not working Iâm kind of giving up here this is killing the site that is using it already.
Can you add more logging? like the url that it is tried to get accessed before it tries to access it.
That is what is only returning from your function with added URL Logging.
logger.info(âerrorâ);
logger.info(tokenUri);
logger.info(httpResponse);
- 2021-10-19T07:32:37.130Z -
- 2021-10-19T07:32:37.130Z -
- 2021-10-19T07:36:24.338Z -
- 2021-10-19T07:36:24.337Z - error
I doesnât look good, can you paste the function that you use now?
function httpGet2(url) {
return Moralis.Cloud.httpRequest({
"url": url,
"headers": {
'method': 'GET',
'accept': 'application/json'
}
}).then(function(httpResponse){
return httpResponse.data;
},function(httpResponse){
logger.info("error");
logger.info(url);
logger.info(httpResponse);
});
}
async function httpGet2(url) {
return await Moralis.Cloud.httpRequest({
url: url,
headers: {
method: "GET",
accept: "application/json",
},
})
.then((httpResponse) => httpResponse.data)
.catch((error) => logger.info(error));
}
this doesnât fail but I see on the console balance is confirmed of the newly created NFT however itâs still in pending table even after confirmation. Iâve tried few times already with same result for some reason.
are they stuck or are in the âpendingâ table for too long?
still stuck until now yes itâs been over 1 hour. despite the log showed confirmed balance.
Iâve created a new server which fixed the problems, but itâs worth mentioning if this was an in production website this would have been a disaster.
when you are using local Ganache you have to create a new Moralis dev server every time you start with a new instance of Ganache, because the old Moralis dev server will still keep track of previous transactions from previous Ganache instance and things will not work well (I donât know if this was your case)