Ethereum Unity3D Boilerplate Questions

hey, you can check this out for calling smart contract functions

you may also have incomplete abi :thinking:

Thanks, Iโ€™ll check it out.

Hello, did you get time to check this ?
Is GetNFTsForContract() working for public address : 0xB65f5Ac5eAD9598f7Ec61c8C89033B970dA7B77D
contract address : 0x81437356a6143f7c344d8569a09607e294ef17a4
on rinkeby testnet on Android build ?

This the one Iโ€™m using;

[
	{
		"inputs": [],
		"name": "getCount",
		"outputs": [
			{
				"internalType": "uint256",
				"name": "",
				"type": "uint256"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [],
		"name": "increment",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	}
]

We are using the latest release (v1.0.8) and this is still happening.

PS: It happens with certain accounts but not all.

The login flow issue is fixed but the error still persists. @dgoodrich

Hello, after I tried this:

    public async UniTask RunContract()
    {
        String ABI = "[{ 'inputs': [],'name': 'getCount','outputs': [{ 'internalType': 'uint256','name': '','type': 'uint256'}],'stateMutability': 'view','type': 'function'},{ 'inputs': [],'name': 'increment','outputs': [],'stateMutability': 'nonpayable','type': 'function'}]";


        MoralisInterface.InsertContractInstance("Test", ABI, "mumbai", "0xc1c1dD559161A527305B276c4C9e156E887368Ce");
        Function f = MoralisInterface.EvmContractFunctionInstance("Test", "mumbai", "getCount");
        //string playerAddress = "0xE1E891fE77ea200eaE62c9C9B3395443cc6ed7bE";
        string result = await f.SendTransactionAsync(addr);
        print(result);
    }

It ran and returned:

RpcResponseException: Internal JSON-RPC error.: eth_sendTransaction
Nethereum.JsonRpc.Client.ClientBase.HandleRpcError (Nethereum.JsonRpc.Client.RpcMessages.RpcResponseMessage response, System.String reqMsg) (at Assets/MoralisWeb3ApiSdk/Nethereum/Nethereum.JsonRpc.Client/ClientBase.cs:40)
Nethereum.JsonRpc.Client.ClientBase+<SendInnerRequestAsync>d__11`1[T].MoveNext () (at Assets/MoralisWeb3ApiSdk/Nethereum/Nethereum.JsonRpc.Client/ClientBase.cs:46)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
Nethereum.JsonRpc.Client.ClientBase+<SendRequestAsync>d__8`1[T].MoveNext () (at Assets/MoralisWeb3ApiSdk/Nethereum/Nethereum.JsonRpc.Client/ClientBase.cs:22)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
ABITest+<RunContract>d__6.MoveNext () (at Assets/MoralisWeb3ApiSdk/ABITest.cs:135)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
Cysharp.Threading.Tasks.CompilerServices.AsyncUniTask`1[TStateMachine].GetResult (System.Int16 token) (at Assets/MoralisWeb3ApiSdk/Plugins/UniTask/Runtime/CompilerServices/StateMachineRunner.cs:218)
ABITest+<Begin>d__4.MoveNext () (at Assets/MoralisWeb3ApiSdk/ABITest.cs:86)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
Cysharp.Threading.Tasks.CompilerServices.AsyncUniTask`1[TStateMachine].GetResult (System.Int16 token) (at Assets/MoralisWeb3ApiSdk/Plugins/UniTask/Runtime/CompilerServices/StateMachineRunner.cs:218)
ABITest+<Test>d__7.MoveNext () (at Assets/MoralisWeb3ApiSdk/ABITest.cs:144)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) (at <695d1cc93cca45069c528c15c9fdd749>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <82c503977c5347cf82f44677f633fcf6>:0)
UnityEngine.UnitySynchronizationContext:ExecuteTasks()

Iโ€™m I doing something wrong?

1 Like

what is the value of addr ?

And have you tried void instead of this ?

Was the contract deployed on the mumbai chain ?

you may also want to look at this, this example works and have been tested , primarily the send snippet


or this if the above fails to work

And passing the ABI that was like a string is supposed to return errors, so you can make it public and pass it through unity
1 Like

Yes itโ€™s deployed to mumbai, addr is user address, Iโ€™ve tried void.
can you guide me on SendTransactionAsync() parameters?
I made ABI a public variable

hey, pls can you take a look at the links i sent, it is pretty clear there

also, this is the boilerplate readme, take a look at it

2 Likes

Iโ€™ve gotten the contract to run using this code:

Function f = MoralisInterface.EvmContractFunctionInstance("test", "mumbai", method);

            HexBigInteger gas = new HexBigInteger(0);
            object[] pars = new object[] { };


            // Call contract function, response is always a string.
            //String resp = await MoralisInterface.GetClient().Web3Api.Native.RunContractFunction("0xc1c1dD559161A527305B276c4C9e156E887368Ce", "getCount", rcd, ChainList.mumbai);
            string resp = await MoralisInterface.SendEvmTransactionAsync("test", "mumbai", method, addr, gas, new HexBigInteger("0x0"), pars);

            print(resp);

now I just need to covert the hash it sends back to a readable string, Thanks

1 Like

well it is supposed to look more like this

// sending custom erc20 specifying gas
 public async void sendCustomTokenwithcustomgas()
 {
//LOL is a unique name, you will see how it is used and set in the boilerplate readme, you can use any name(i used LOL), 
//ABI is the contract ABI (it is public so i set it through unity,
// rinkeby is the chain my smart contract is deployed on and the chain i connect to with wallet connect
// The address is the address of the smart contract deployed on rinkeby
     MoralisInterface.InsertContractInstance("LOL", ABI, "rinkeby", "0xfF75215204108992CFc2e902E560D461776BC906");
     //gas estimate for the transaction
     HexBigInteger gas = new HexBigInteger(80000);
     string recieverAddress = "0xE1E891fE77ea200eaE62c9C9B3395443cc6ed7bE";
     string senderAddress = "0x37Ad540C876FceCf80090493F02068b115dDf8B6";
// This is the argument of any transaction, in this case transfer(address to, uint amount)
     object[] pars = { recieverAddress, 20};
     // This will call the smart contract fucntion
// LOL is that same sam key i used as before (it is required the same key is used for the same instance)
// rinkeby is my chain
// The function i am calling is the `transfer` function from my smart contract (with the abi), you can place any function name here
// The sender of the Function, usually the address returned from the wallet connect connection (in solidity msg.sender or tx.origin lol but not in this case ๐Ÿ˜…)
// That is the gas we are using, we set it above
// well nothing much to explain ๐Ÿ˜…
// The arguments the function transfer takes, we also set that above
     string result = await MoralisInterface.SendEvmTransactionAsync("LOL", "rinkeby", "transfer", senderAddress, gas, new HexBigInteger("0x0"), pars);
// This will return the tx hash as a string
     print(result);
 }

This should give you an overview of how it is done, you can take a look at the boilerplate readme anything you dont understand you can ask here

1 Like

How do you run a cloud function from Unity?

Edit:

IDictionary<string, object> pars2 = new Dictionary<string, object>();

ResourceResponse resourceResponse = await MoralisInterface.GetClient().Cloud.RunAsync<ResourceResponse>("getCount", pars2);
1 Like

What you have there is correct.

For example, for authentication the server time must be retrieved by calling a cloud function. This is the code for that:

        // Retrieve server time from Moralis Server for message signature
        Dictionary<string, object> serverTimeResponse = await MoralisInterface.GetClient().Cloud.RunAsync<Dictionary<string, object>>("getServerTime", new Dictionary<string, object>());

So your code looks good. Are you observing any errors?

Hi guys, I have a question.
With my current login flow (android, metamask), user is redirected to metamask with deeplink, than he needs to go back to app and is redirected to metamask again, is there a way so user doesnโ€™t need to go back to app?

2 Likes

++++ for this question been willing to ask that one for a while.

1 Like

Unfortunately no. When the user is re-directed, WalletConnect / Unity goes to sleep. So the navigation back to the app allows it to wake so it can process the response and then send the signature request.

Hi there.

managed to get ERC20 transaction work perfectly with the SendEvmTransactionAsync.
Now I am trying to get infos about my NFT pricing.
My contract function has one input argument (OfferID) and should return 5 outputs like shown below:
Capture dโ€™eฬcran 2022-03-05 aฬ€ 19.59.34

Was thinking of using the SendEvmTransactionAsync but I am not trying to make a transaction, just need to run a specific contract function. Despite the readme git, I canโ€™t figure out how to use the RunContractFunction method.

Any help would be super greatful as my marketplace will need lots of function calls :slight_smile:

Thnaks

So my suspicion was correct, but wanted to ask anyway if I miss some possible solution :wink: thanks for answer