Ethereum Unity3D Boilerplate Questions

Can I use your example for the paid transaction in webgl.
I want to call this Openzeppelin ERC20 function:

My code in Unity:

            object[] inputParams = new object[2];
            inputParams[0] = new { internalType = "address", name = "spender", type = "address" };
            inputParams[1] = new { internalType = "uint256", name = "addedValue", type = "uint256" };

            // Function ABI Output parameters
            object[] outputParams = new object[1];
            outputParams[0] = new { internalType = "bool", name = "", type = "bool" };

            // Function ABI
            object[] abi = new object[1];
            abi[0] = new { inputs = inputParams, name = "increaseAllowance", outputs = outputParams, stateMutability = "nonpayable", type = "function" };

            // Convert token id to hex as this is what the contract call expects
            object[] pars = new object[] { abi.ToString() };
            // Contract address, abi, function name, pars, value, gas, gas price
            string result = await MoralisInterface.ExecuteContractFunction(contractAddress, abi, functionName, pars, new HexBigInteger("0x0"), gas, gas);
1 Like

I tested MoralisInterface.ExecuteContractFunction on WebGL and it is not working, I get no respose. It works on the PC version but I get no response on WebGL.

string result = await MoralisInterface.ExecuteContractFunction(contractAddress, abi, "approve", pars, new HexBigInteger("0x0"), gas, price);

Please tell me can I call paid function from WebGL? I can’t find any example to call a paid transaction on WebGL. @dgoodrich @0xprof

Hi there !
Having strange behaviors since a week…
1 - When I check the NFT owned by an address there is always a big delay between when the transaction is confirmed and when I can display it in game.
In here, and on the server log we can see that the transaction is made at 5:50pm:


But on the screenshot it only appears in game 13minutes later.

any idea why is that ?

2- also, the log shows a total of 1 NFT when we clearly see two results ?

3- Why some erc1155 shows token_url, others don’t ? (when I can both check the url on remix without pb)

Thanks for your help !

PS: did an other test and had to wait exactly 13minutes again before displaying it in-game.

hey, to pass in msg.value
use new HexBigInteger("0x0") this is what you edit, right now 0x0 means no value, you can change it if the function takes msg.values

And

string resp = await MoralisInterface.ExecuteContractFunction(Constants.MUG_CONTRACT_ADDRESS, Constants.MUG_ABI, Constants.MUG_CLAIM_FUNCTION, pars, new HexBigInteger("0x0"), gas, gas);

This should work, it is the same on the boilerplate

why is here price ?
it is supposed to probably be more gas :sweat_smile:, try passing it as gas, i gave an explanation here

1 Like

Interesting , must be delay in endpoint
1).
so let me get this
you created an nft (idk how, but you did)

then you called getNFT in your code (or you check the web3api test area at https://admin.moralis.io/web3Api ) : and didn’t display the NFT ?

Then you waited 13 minutes and probably repeated the above step and it seem to have fetched and display it ?

2). Interesting lol, i will check on this, it seem to be problems with the api pos chain

3). maybe those have not properly been fetched, another problem with the api on pos chain, there are some case the metadata field are empty, that is understandable, but the token_uri should be available (it is recommended nft metadata are fetched from the token_uri)

in conclusion, it maybe due to the overload on the pos chain causing it to be slow, i will report it to the team.

ok, so looking at the contract,

  {
      "token_hash": "74fca4e71f8d3f2bb04cd2c522256716",
      "token_address": "0x52ecdbd3faf7ed638d0ad4f90b5435cbfdc41aec",
      "token_id": "1",
      "block_number_minted": "26121313",
      "amount": "100",
      "contract_type": "ERC1155",
      "name": null,
      "symbol": null,
      "token_uri": "https://lh3.googleusercontent.com/yoJkJVTLTJsMi0sqkGWCyR2sOgpmhikg4SYQKXcUhAXVvKiHPSeeP4nIldg-oEX9FW_q7Uh8VGa9wlI7zanKTFKu9Fw4Y3D0tdlsfA=w600",
      "metadata": null,
      "synced_at": "2022-04-28T19:27:16.494Z"
    },

This is one of the result, i check the token_uri, it is an image, so a metadata json cannot be created, hence metadata field is null (metadata are in form of json example)

and the it looks like you contract has no name and symbol hence name and symbol been null and it is erc 1155, which is correct

hope this explains some other things, what you experienced earlier was mumbai pos chain been overcrowded its, but it should be ok now

Hi there you guys did allot of work. I have a question can i replace the nft that comes out of the box in the sample. With the one i made on opensea? If so is it as simple as change the current nft’s adress and tokend id?

The 3d mug that comes out of the box is inside from the demoscene and it is minted on-chain on the win. You will need to change this to your NFT that you want to mint on winning.

image

thank you can that nft be created on opensea?

Yes. The Mug is actually an erc1155 token which is on opensea. You can add the parameters of your NFT in unity.

However the 3d mug is only from the unity. I guess only image is minted on chain.

When change the morlismug to my nft. It wont work…
This is the nft i want to drop nft url I tried to change the mug nft token id and the contract adress, I also changed the MUG_CONTRACT_ADDRESS = in the Constants.cs to the adress that created the nft on opensea. It says transaction succes but i dont get the nft dropped.

Did you get any transaction address on your wallet to check if the transaction happened?

no i did not. But I found out wye. If you make the nft directly on the opensea platform it wont work you need to make a custome contract. Any1 got a sample or a refferance?

yes, it wont,
you have to have a custom contract so you can call contract functions, and also all nfts created by your contract shows up on opensea, that is how the mug was done

Hello everyone, I have a problem, this code works fine on a PC build, but on a WebGL build, this part of the code does not work and gives this error. As I understand it, I am authorized on the server, but for some reason saveasync dont work (404)

async void Update()
{
if (!isInitialized && MoralisInterface.Initialized && MoralisInterface.IsLoggedIn())
{
SaveObjectToDB();
}

public async void SaveObjectToDB()  //Создаем дату первый раз
{
    
       MoralisUser user = await MoralisInterface.GetUserAsync();
    string addr = user.authData["moralisEth"]["id"].ToString();

#if UNITY_WEBGL

    MoralisQuery<SaveAndDataSystem.PlayersData> q = await MoralisInterface.GetClient().Query<SaveAndDataSystem.PlayersData>();
    MoralisQuery<SaveAndDataSystem.PlayersData> playerDataCheck = q.WhereEqualTo("Contract", addr);
   IEnumerable<SaveAndDataSystem.PlayersData> result = await playerDataCheck.FindAsync();

#else
MoralisQuery<SaveAndDataSystem.PlayersData> playerDataCheck = MoralisInterface.GetClient().Query<SaveAndDataSystem.PlayersData>().WhereEqualTo(“Contract”, addr);
IEnumerable<SaveAndDataSystem.PlayersData> result = await playerDataCheck.FindAsync();
#endif

    Debug.Log("123 "+addr);
    Debug.Log("1233 " + user);
    if (result == null || result.Count()<= 0)
    {
        SaveAndDataSystem.PlayersData playerData =  MoralisInterface.GetClient().Create<SaveAndDataSystem.PlayersData>();
        playerData.ACL = new MoralisAcl(user);
        playerData.Contract = addr;
        playerData.Crystals = 0;
        playerData.UserName = "NewPlayer";
        playerData.CharsItemsData = "";
        playerData.HikeData = "";
        await playerData.SaveAsync();
   }
}
  1. I found solution… I add this to class

  2. [7:37]

public class PlayersData : MoralisObject { this => public PlayersData(): base (“PlayersData”) {} …

Hi all,

Any way we can use magic link to authenticate ??
I have seen a video showing its possible for web dapps not for unity. Any idea how to do that ?
Thanks a lot !

1 Like

Hello everyone,
How can I execute a payable function through the new MoralisSDK?
The function Moralis.SendEvmTransactionAsync doesn’t work

Magic Link isn’t possible yet.