Ethereum Unity3D Boilerplate Questions

you cannot write contracts in unity and you cannot use moralis to write contract

you should take a intro to contracts here
and watch this to be familiar with smart contract before you start integrating them into your projects

Hi everyone, last week I had been using version 1.0.9 and this week it suddenly stopped working, the connect message is coming but the sign message never comes, is there a reason for this issue?

I tested the SceneDemo of this version (1.0.9) and it does not work too.

Yes but with HexBigInteger it says :

Ensure the value is valid for the abi type.
So I believe at contract level BigInteger is right ?
Even when I hardcode the amount with digits it result to the same error …

I am sure to have enough balance, tried with very small values and “0” and still get the same error.

On new SDK version, the two methods :

MoralisInterface.InsertContractInstance()

and

MoralisInterface.SendEvmTransactionAsync()

seem deprecated/obsolete. having new warinings there.
In the MoralisInterface, there is this line now line.535 and 575:

[Obsolete("This method is deprecated. This method will not be replaced.")]

Don’t know if this is the reason.

InsertContractInstance and SendEvmTransactionAsync methods are working, don’t mind the warnings. I don’t know why they put Obsolete there in the last version for no reason.

1 Like

Here is the function that I am using with no issue. Hope it helps you.

// MoralisInterface.InsertContractInstance("transfer", ABI, chainId, erc20ContractAddress);
public async void SendERC20()
    {
            Function f = MoralisInterface.EvmContractFunctionInstance("transfer", chainID, "transfer");
            HexBigInteger gas = new HexBigInteger(80000);
            string result = await f.SendTransactionAsync(fromAddress, gas, new HexBigInteger("0x0"), receiver, amount);
            Debug.Log(result);
    }
1 Like

Basically we are trying to standardize how Web3 works in both WebGL and non-WebGL We are discussing about the merits of keeping the Contract related methods (not the two SendTransaction methods) and implementing equivalents for WebGL.

2 Likes

Hi there,
Could you suggest how i can make an “auto create wallet” function ?
That would generate a wallet within the game ?
I saw a few solutions out there, but wanting to know if there is a moralis solution :slight_smile:
thanks !

I do not know if you have solved this problem, but I solved it this way:

  1. Find 2 of your WebSockets and open them (you can use notepad)
  2. Copy the entire text from any WebSockets and paste it at the end of the second one, saving the changes. The first WebSockets will need to be deleted later.

Hi
i got question How to wait for transaction confirmation for Unity webGL?

I have moved from this thread

I use this function to execute smart contract function in Unity WebGL

string resp = await MoralisInterface.ExecuteContractFunction(Constants.ADDRESS, Constants.ABI, Constants.Func_Mint_Token, pars, v, gas, gas);

no error but it return a transaction hash string. not wait for transaction confirmation.
There is nothing response when the transaction have confirmed or failed.

I found that React can do this but I’m not found how to do in unity

The string resp is just a string. cannot await resp.wait()

How should I approach adding this sdk to an existing Unity 2D game?

I have a 2D game that needs to authenticate via Web3. User can be on Eth, polygon or Avax. Upon completion the user will update a contract on their respective chain.

Seems like the best way is to implement Web3 auth and use cloud functions to make the smart contract calls on level completion.

With that functionality in mind, what necessary packages should be imported and where should moralis related code live withing the Unity project? currently working with a 2D project.

You can use the Moralis Unity SDK for authentication and running contract calls. You can download the latest version here and there’s a tutorial on using it here.

yes, the current method doesn’t do this, and idt you can wait it

@dgoodrich How to listen callback when user switch network on metamask in unity webgl?

Thank you

That isnt currently implemented but it will be in a future update

ok…
I think i have to check transection overtime untill get the result.

Hi. I have this problem too, what was the solution? THX!

webgl connection only works on build, it will through that error when running it on the editor

Thanks for reply,
I hope this will be available soon. :crossed_fingers:

I can’t use MoralisInterface.EvmContractFunctionInstance and InsertContractInstance on WebGL build. What Can I use instead of it?

Example:
Function f = MoralisInterface.EvmContractFunctionInstance("approve", chainId, "approve");

try something like this

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

//contract address, abi,function,parameters,msg.value,gas,gas,

1 Like