Ethereum unity boilerplate

Keep getting this error on the right saying the script canā€™t be loaded. Any idea why?

1 Like

Usually happens when there are errors. Look at the ā€œConsoleā€ pane to see if you have an error about ā€œunsafeā€ code. If so please read through the setup steps in the readme. There is a setting required by Nethereum.

Hey! how can i call my Smart contract function?, I tried using -> RunContractFunction(string address, string functionName, RunContractDto abi, ChainList chain, string subdomain=null, string providerUrl=null) method in nativeApi (Api namespace and not the cloud one) but its throwing error when calling from unity
(error : ApiException: Error calling RunContractFunction: Error: ConnectFailure (No connection could be made because the target machine actively refused it.))
Our contract is basically storing some amount and then the other user can retrieve that amount from smart contract so the storing part is working fine ( for storing we used MoralisInterface.SendEvmTransactionAsync(arguments) ) but this same funtion is not workable for retrieve function from smart contract which has no arguments.

1 Like

David,

Any update on WalletConnect issue being resolved. When I donā€™t select a default wallet inside the SDK on Unity. Iā€™d like all the wallets on WalletConnect to populate. We donā€™t want our users to be limited to only one wallet. When i do this and play the scene the game takes forever when trying to find a wallet to connect with.

Iā€™d like to have a popup window that comes up a displays the wallets that WalletConnect supports.

Thoughts?

1 Like

Thank! for your response,
I just wanted to send Native coins ETH/BNB etc OR Bep-20 tokens to one meta-mask wallet to another how I do this?
The 1 line code to send ETH/BNB provide on documentation, I tried as shown in figure but its not working.
can you please guide me where I made mistake ? or any other simple way of doing this

1 Like

HI, you do not need to instantiate MoralisClient directly, this is done for you in MoralisINterface - please see the Moralis/Unity README.

Also Moralis.transfer is a JS SDK call. The Moralis / Unity SDK equivalent is the MoralisInterface.SendEvmTransactionAsync or MoralisInterface.SendTransactionAndWaitForReceiptAsync functions I described to you earlier.

Here is an example from the README that shows how to run a read only function on a contract:

// Function ABI input parameters
object[] inputParams = new object[1];
inputParams[0] = new { internalType="uint256", name="id", type="uint256" };
// Function ABI Output parameters
object[] outputParams = new object[1];
outputParams[0] = new { internalType="string", name="", type="string" };
// Function ABI
object[] abi = new object[1];
abi[0] = new { inputs=inputParams, name="uri", outputs=outputParams, stateMutability="view", type="function" };

// Define request object
RunContractDto rcd = new RunContractDto()
{
    Abi = abi,
    Params = new { id = "15310200874782" }
};

// Call contract function, response is always a string.
string resp = MoralisInterface.GetClient().Web3Api.Native.RunContractFunction("0x698d7D745B7F5d8EF4fdB59CeB660050b3599AC3", "uri", rcd, ChainList.mumbai);

For iOS ONLY: At design time select all of the wallets listed in the iOS wallet menu. Please be advised that due to how Wallet Connect loads the images it may take over a minute for the selection menu to appear, I have no control over this - this is why I added the selection tool.

Which issue are you referring to?

Thanks,

David

Can you share exact code of how to send Eth/Bnb in unity3d from one wallet to another,
new here and didnā€™t understand all of these stuffs. Thanks

David, how do you require the wallet to open up. Iā€™ve noticed that when a smart contract is interacting with Unity and it requires me to sign and approve. The wallet doesnā€™t open automatically to do thatā€¦ I have to know that an event SHOULD be happening. Then I need to switch over to my wallet. Once I do that I can see my wallet is waiting for me to perform an action like approve and signā€¦

Any advice as to how I can get the wallet to automatically open. Thatā€™s not really user friendly if you ask me.

1 Like

Here is an example from the README that shows how to run a read-only function on a contract:
there is no relevant data available on README!

also, I want to execute External functions in a smart contract that has no argument, in short Other than the Read-Only function.

Hereā€™s the test smart contract which we are trying to callā€¦ in it, thereā€™s a function called ā€œwithdraw()ā€ which I need to call from unity.
https://www.toptal.com/developers/hastebin/sufivinesi.typescript

If you have set up Nethereum properly and are calling a Nethereum function that interacts with a contract in a way that changes state, it will automatically open your wallet.

With the release of the 1.0.3 package a few weeks ago, Nethereum was integrated into the MoralisInterface. Please see the example I provided in the ClaimRewardAsync method of the AwardableControler.cs file. The code to claim the reward is here and serves as a demonstration of how to call a contract function that changes state. When called the wallet will automatically open.

The MoralisInterface in v1.0.3 automatically setups the Web3 (Nethereum) connection for you if you provide an RPC URL (please refer to the README).

Regards,

David

Yes there is! Here is the direct link to that section of the README: RunContractFunction.

With the release of the 1.0.3 package a few weeks ago, Nethereum was integrated into the MoralisInterface . Please see the example I provided in the ClaimRewardAsync method of the AwardableControler.cs file. The code to claim the reward is here and serves as a demonstration of how to call a contract function that changes state.

You should look through the code called by MoralisInterface.SendEvmTransactionAsync to see how this code is interacting with Nethereum. I also advise you to read through the Nethereum documentation.

Here is how to specifically use the MoralisInterface to call your contract

  1. Read this README section
  2. Register your contract in the provided contract manager. From the MainMenuScript.cs InitializeWeb3 method:
       MoralisInterface.InsertContractInstance("MyContract", "[MY ABI STRING HERE]", "[TARGET CHAIN KEY]", "[CONTRACT ADDRESS ON TARGET CHAIN]");

Substitute your values to represent your contract
3. Call the function like this:

        Nethereum.Contracts.Function func = MoralisInterface.EvmContractFunctionInstance("MyContract", "[TARGET CHAIN KEY]", "MyFunctionName");
        object[] pars = new object[0];
        string jsonResult = await func.CallAsync(pars);

The jsonResult is whatever is returned from your contract by the call.

Regards,

David

Hi there !
Digging your AwardableController script, amazing stuff!
Is there a way to have a glimpse at the smart contract ? or template ?

It seems strange that the player has to sign the transaction when claiming the nft. Is to make him pay the fees ?
also, i am interested in how you automated the transfer from the contract (and contract owner) to the player (without having to sign each transaction manually)

Thanks a lot !