Web3 First Person Shooter - Helping Each Other

Yes I should have clarified that earlier, I was under the assumption that you had created your own contract that was then listed on OpenSea since you were swapping it out.

Possibly the source code of the contract is available, I’m not finding it in the repo however. Can you post the sample contract address? I don’t know enough about this tutorial/project to see if there’s a similar base contract you could use.

Here is link to the nft thats is used in the tutorial
nft url
contractadress: 0x698d7D745B7F5d8EF4fdB59CeB660050b3599AC3
Tokenid : 0x698d7D745B7F5d8EF4fdB59CeB660050b3599AC3

thanks you saved me so many headaches. i tried this without the json edit on my desktop and my goodness so many errors. i did this on my laptop and works perfectly.

1 Like

Glad I helped :slight_smile:

Hello, I am trying to implement the ClaimNFTcontroller.cs in my own project. I imported all the files from the Web3SpaceShooters directly, however I still get this compile error:

Assets\MoralisWeb3ApiSdk\Moralis\ClaimNftController.cs(138,54): error CS0117: ‘MoralisInterface’ does not contain a definition for ‘SendEvmTransactionAsync’

I did not change any code in the C# file, and the file has no errors in the demo project. What is going on here?

1 Like

Hi @ardawarcraft and first of all, welcome to the Moralis Unity community :slight_smile:

What version of the Moralis SDK do you have installed in your own project?

Thanks!

Hi, thank you :slight_smile:

I do not know what version because I directly copied the MoralisWeb3ApiSdk folder fully from the Demo project to My project. I think the specific github directory is this, https://github.com/MoralisWeb3/youtube-tutorials/releases/tag/v1.0.0-unity-web3-spaceFPS , whatever version is used here I use the same because I copy pasted it from there anyway

Hi @ardawarcraft!

Is there any other MoralisInterface function getting the same definition error or just SendEvmTransactionAsync?

Thanks!

Hi @dpradell actually yes there is 1 more. ''Assets_Project\Scripts\Moralis\MoralisWeb3Manager.cs(153,30): error CS0117: ‘MoralisInterface’ does not contain a definition for 'InsertContractInstance"
and the other, as you mentioned correctly, is
“Assets_Project\Scripts\Moralis\ClaimNftController.cs(138,54): error CS0117: ‘MoralisInterface’ does not contain a definition for ‘SendEvmTransactionAsync’”

@dpradell

@dpradell important note::

this compile error only shows up after the GameManager.cs file is deleted. The reason why it was deleted was this error:

Assets_Project\Scripts\GameManager.cs(43,53): error CS0311: The type ‘Main.Enemy Data’ cannot be used as type parameter ‘T’ in the generic type or method ‘Moralis LiveQuery Callbacks’. There is no implicit reference conversion from ‘Main.EnemyData’ to ‘Moralis.WebGL.Platform.Objects.MoralisObject’.

maybe if we can fix this compile error and not have to erase gamemanager script, we can fix both

Hi @ardawarcraft!

Ok so now I know what’s happening. The thing is that copying an SDK folder from a Unity project to another it’s not usually a good practice. When you do that you expose yourself to lose some dependencies on the way.

So the way I would solve this is by doing the following:

  1. If you can, start a fresh new project.

  2. If not, in your current project, delete all the files that you imported from the Web3 Space FPS project, including the SDK folder, the ClaimNftController and all the files that are generating errors.

  3. Import the NEW version of the Moralis Web3 Unity SDK from our GitHub:

  4. To import it, copy the HTTPS link and use Add package from Git URL on the Unity Package Manager:

  5. Once the new version of the SDK is imported, you can then copy the ClaimNftController.cs from the Web3 Space FPS project. It will generate some errors because we don’t use MoralisInterface anymore but just Moralis and also some namespaces have changed so you will need to change every MoralisInterface to Moralis and also change some namespaces. Probably these are the ones that you will need to add:

using MoralisUnity;
using MoralisUnity.Platform.Objects;
using MoralisUnity.Web3Api.Models;
  1. After you do so, in order to use ClaimNftController.cs you will first need to authenticate to Moralis so you can take a look at how this is done using the new version of the SDK watching this video: https://www.youtube.com/watch?v=3Mw1tDu9gak&t=9s

I hope this is helpful. Let me know on your progress.

David

1 Like

@dpradell Hi David,

thank you very much for your detailed response. It makes a lot, lot more sense now. Thank you


I also noticed that SendEVMTransactionAsync is deprecated and there is a new SendTransactionAsync method. When I use the new method, I get this error:

Assets\Scripts\Moralis\ClaimNftController.cs(138,45): error CS1501: No overload for method ‘SendTransactionAsync’ takes 7 arguments
this is what I have now that gives the error,
string resp = await Moralis.SendTransactionAsync(“Rewards”, “mumbai”, “claimReward”, _walletAddress, gas, new HexBigInteger(“0x0”), pars);
and I think it should be formatted like this;;;
(string recipientAddress, HexBigInteger value, HexBigInteger gas = null, HexBigInteger gasPrice = null)

What should I change my variables to? I currently did (“Rewards”, gas, HexBigInteger(“0x0”), pars); and got the following error :
== Assets\Scripts\Moralis\ClaimNftController.cs(138,82): error CS1503: Argument 3: cannot convert from ‘object[]’ to ‘Nethereum.Hex.HexTypes.HexBigInteger’

thank you for all the help :slight_smile:

Hi @ardawarcraft,

I’m glad that I helped. And true, SendEvmTransactionAsync is deprectated in the new version of the SDK so I would use ExecuteContractFunction instead. For parameters, you will pass the same object pars as the function of the contract didn’t change, but some other parameters may vary.

I encourage you to watch the new Moralis Project video releasing tomorrow 10:00 am CET where I’m explaining exactly how to use this function with the new version of the SDK.

Cheers!

David

1 Like

Hi David!

I watched the video but I still have trouble writing a C# method for ExecuteContractFunction that does the claim, specifically using pars. But I get lots of errors and I do not really know how to structure it like
public async static UniTask ExecuteContractFunction(string contractAddress,
string abi,
string functionName,
object[] args,
HexBigInteger value,
HexBigInteger gas,
HexBigInteger gasPrice)
{
string result = null;
string gasValue = gas.Value.ToString();
string gasPriceValue = gasPrice.ToString();

        if (gasValue.Equals("0") || gasValue.Equals("0x0")) gasValue = "";
        if (gasPriceValue.Equals("0") || gasPriceValue.Equals("0x0")) gasPriceValue = "";

        try
        {

#if UNITY_WEBGL
string functionArgs = JsonConvert.SerializeObject(args);
result = await Web3GL.SendContract(functionName, abi, contractAddress, functionArgs, value.Value.ToString(), gasValue, gasPriceValue);
#else
// Retrieve from address, the address used to authenticate the user.
MoralisUser user = await Moralis.GetUserAsync();
string fromAddress = user.authData[“moralisEth”][“id”].ToString();

            Contract contractInstance = Web3Client.Eth.GetContract(abi, contractAddress);
            Function function = contractInstance.GetFunction(functionName);

            if (function != null)
            {
                result = await function.SendTransactionAsync(fromAddress, gas, value, args);
            }

#endif
}
catch (Exception exp)
{
Debug.Log($“Call to {functionName} failed due to: {exp.Message}”);
}

        return result;
    }

what would be a better way for me to call pars using ExecuteContractFunction because the names in the new video are different, I am not that experienced with connecting to the blockchain with Unity

Hey, this is a great tutorial.
I am trying to run it but failed. Anyone can help me?
The first step passed - Scanning QR code using my mobile wallet (Trust Wallet)
The second step is not passed. “please sign authentication message in your wallet”
I confirmed console logs. Here it is.

Sending sign request for 0x941ef5cce9d3889215e6f6eb8600864680f959f6 

[WebSocket] Exception Unexpected character encountered while parsing value: M. Path ‘’, line 0, position 0.



Hi @khk.cryptech and welcome to the community.

Try using MetaMask and have the Mumbai testnet imported with some funds in it:

Hello everyone! When transferring the files of this project to another project, I got two errors:(
The first:
Assets\NFT\ThirdParty\NavMeshComponents\Editor\NavMeshAssetManager.cs(44,73): CS1061 error: ‘PrefabStage’ does not contain a definition for ‘assetPath’ and could not find an available ‘assetPath’ extension method that accepts the first argument of type ‘PrefabStage’ (are you missing a using directive or an assembly reference?)

The second:
Assets\NFT\ThirdParty\NavMeshComponents\Editor\NavMeshAssetManager.cs(46,81): CS1061 error: ‘PrefabStage’ does not contain a definition for ‘assetPath’ and an available ‘assetPath’ extension method could not be found that accepts the first argument of type ‘PrefabStage’ (are you missing a using directive or an assembly reference?)

Screenshot of the error code:

Thank you in advance for your help!:slight_smile:

What files/folders did you copy over exactly and how did you do it?

Have you found the solution. I’m also stuck with the same problem. When tried to replace my own nft minted on opensea by changing the contract address and token id in ClaimNftcontroller editor, got invalid json rpc error failed eth transaction. Also when deployed ERC1155 smart contract after changing mint function to claimreward, and changed the details in constants.cs file, got claimreward function not found error.