Ethereum Unity3D Boilerplate Questions

Yes. I imported the template from v1.1.0 and then it showed me the WebGL template. It works for me. Give it a try.

sure thing…thanks my friend i will try this

the thing that annoys me is that there is nothing in the tutorial to say this or try this.

i followed the tutorial with the knight demo and it works fin but i now need to add this to my own game so i am having this issue with Web GL template. very annoying…

thanks again i will try this

1 Like

How to get address user call cloud function, add logout user with address

The type or namespace name ‘JsonProperty’ could not be found (are you missing a using directive or an assembly reference?)

https://docs.moralis.io/unity
follow the guides on setting up the sdk, there is a solutions to webgl on the latest version, pls alway look at the docs

For some here having issues not finding the WebGL template under Player Settings:

Hello if you have problems or questions that you solve on your own, it would be great if you kept or updated your posts for other users.

Hi there, apologies, it is because I have posted it on your discord and thought it was redundant.
But problem still remains:
using this code to mint nfts ingame, but the value of the transaction displayed on metamask is different from the amount i set in unity :

private async Task<string> PurchaseItemFromContract(BigInteger tokenId, string metadataUrl)
    {
        byte[] data = Array.Empty<byte>();


        object[] parameters = {
            
            amountMint = 1
        };

        
        decimal price = 0.01m;
        BigInteger cost = UnitConversion.Convert.ToWei(price);
        Debug.Log(cost);
        HexBigInteger amount = new HexBigInteger(cost);
        Debug.Log(amount);

        HexBigInteger gas = new HexBigInteger(80000);
        HexBigInteger gasPrice = new HexBigInteger("0x0");

        string resp = await Moralis.ExecuteContractFunction(GameManager.ContractAddress, GameManager.ContractAbi, "mint", parameters, amount, gas, gasPrice);
        
        return resp;
    }

Any idea would be most welcome :slight_smile:

specify the decimal in the conversion

https://docs.moralis.io/moralis-dapp/tools/moralis-units

Yes already tried that but does not change anything unfortunately

have you sent the transaction and see what it actually took ?

sure, It obviously fails as the amount is lower than the price i setup in my smart contract.
it looks like this :

with a value of 0.000000830806853155 MATIC instead of 0.001.

hey, probably there is something wrong, have you tried other networks ?

why did the transactions fail ?, pls try other networks to see if it is only matic, you can also try testnet

drop steps to reproduce if you still cant get it working, i have tried it and it works ok on my end

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

Ok solved it.

Moralis.Cloud.define("UserNFTFrameChoiceCheck2", async (request) => {
	var a1 = request.params.XoneId;
	const query = new Moralis.Query("UserNFTFrameChoice");
	query.equalTo("XoneId", request.params.XoneId);
	var results = await query.find();
	var resp = {a1: JSON.stringify(results)}; 
	return resp;
  }, {
	fields: ['XoneId'],
});

Unity side required this:

public class CloudFunctionResult
{
    public string a1;
}
 CloudFunctionResult r = await MoralisUnity.Moralis.Cloud.RunAsync<CloudFunctionResult>("UserNFTFrameChoiceCheck2", pars3);
1 Like

Hi,

@dgoodrich I am getting this error when running client-side code (for reference the cloud function that does the same works ok). This code was running fine till yesterday. Looks like a problem with chainlist. Can you inspect?

**Failed running cloud function getNFTsForContract for user undefined with:**
1. **Input: {"address":"0xff29709093c8f73c00912f0ee1ffc683c8870b6c","token_address":"0x9Ec46a3dd227Fd5977C7F1997C043122a703FF2A","chain":"0x1"}**
2. **Error: {"message":"Cannot read properties of undefined (reading 'chain')","code":141}**

Thank you in advance

have you check your code ?
this error message: "Cannot read properties of undefined (reading 'chain')" says something reading chain is undefined can you take a look at that

Hello! guys I ran into a very weird issue, the SDK is not storing correctly the App URL and App ID in the moralis settings, every time I try to add it when I hit play is gone and it request it again, let me know if some have run into this issue and how to fix this

unity version 2021.3.0f1
moralis SDK version 1.2.3

Can you try changing the server settings in the MoralisServerSettings script (Assets > Moralis Web3 Unity SDK > Resources)? Also maybe try a slightly newer version of Unity like 2021.3.2 or 2021.3.4.

Anybody tried adding meta transactions? Any help will be appreciated?