Hi @dgoodrich,
Can you help me out with a working example of Cloud Function that returns NFTs?
So far I have this in cloud:
// ### GENERAL TEST FUNCTIONS START
//works
Moralis.Cloud.define("helloworld", async (request) => {
return "hello beautiful world";
});
//works
Moralis.Cloud.define("addOneTest", async (request)=>{
var a = request.params.arr1;
a +=1;
//var resp = {a: stringify(a)};
return a;
}, {
fields: ['arr1']
});
// ### GENERAL TEST FUNCTIONS END
// ### NFT GETTER FUNCTIONS START
//returns [object Promise]
Moralis.Cloud.define("getUserNFTs", async (request)=>{
var userEthNFTs = await Moralis.Web3API.account.getNFTs().toString();
return userEthNFTs;
}, {
fields: ['arr1']
});
//returns {"code":141,"error":"Cannot convert undefined or null to object"}
Moralis.Cloud.define("getUserNFTs2", async (request)=>{
const userEthNFTs = await Moralis.Web3API.account.getNFTs();
return resp;
}, {
fields: ['arr1']
});
//returns {"code":141,"error":"Cannot convert undefined or null to object"}
Moralis.Cloud.define("getUserNFTs3", async (request)=>{
var u = request.params.arr1;
u = await Moralis.Web3API.account.getNFTs();
return u;
}, {
fields: ['arr1']
});
// ### NFT GETTER FUNCTIONS END
// ### QUERY FUNCTIONS START
//JsonReaderException: Unexpected character encountered while parsing value: [. Path '', line 1, position 1.
Moralis.Cloud.define("UserNFTFrameChoiceCheck", async (request) => {
const query = new Moralis.Query("UserNFTFrameChoice");
query.equalTo("XoneId", request.params.XoneID);
const results = await query.find();
return results;
});
// ### QUERY FUNCTIONS END
… and this to call it in Unity:
NftOwnerCollection n = new NftOwnerCollection();
Dictionary<string, object> pars = new Dictionary<string, object>();
pars.Add("arr1", n);
//pars.Add("arr1", null);
//returns promise Object
string s = await MoralisUnity.Moralis.Cloud.RunAsync<string>("getUserNFTs", pars);
Debug.Log($"getUserNFTs result :: {s}");
//returns {"code":141,"error":"Cannot convert undefined or null to object"}
s = await MoralisUnity.Moralis.Cloud.RunAsync<string>("getUserNFTs2", pars);
Debug.Log($"getUserNFTs2 string result :: {s}");
//returns {"code":141,"error":"Cannot convert undefined or null to object"}
s = await MoralisUnity.Moralis.Cloud.RunAsync<string>("getUserNFTs3", pars);
Debug.Log($"getUserNFTs3 string result :: {s}");
Dictionary<string, object> pars3 = new Dictionary<string, object>();
pars3.Add("XoneID", "2503");
s = await MoralisUnity.Moralis.Cloud.RunAsync<string>("UserNFTFrameChoiceCheck", pars3);
Debug.Log($"UserNFTFrameChoiceCheck string result :: {s}");
//empty
UserNFTFrameChoice ch = await MoralisUnity.Moralis.Cloud.RunAsync<UserNFTFrameChoice>("UserNFTFrameChoiceCheck", pars3);
Debug.Log($"UserNFTFrameChoiceCheck UserNFTFrameChoice result :: {ch.ImageUri}");
My goal is to have it naturally deserialized or at least as JSON object. Not a fequent JS user BTW.
Thanks in advance