Ethereum Unity3D Boilerplate Questions

Not sure what advice to give here other than try again. Looking at the image again, I do not see which package it is reporting on. Please copy the text of the error and post it.

1 Like

Something is not right there. After you install the package everything should be under Assets/MoralisWeb3ApiSdk. I could not find the folder or dll referenced.

Did you install by downloading the 1.0.2 package from github?

Thanks,

David

Ok, so I deleted the other folders I had downloaded and only kept the MoralisWeb3Apisdk. Works fine now with few issues, but let me tinker around and understand. Thanks.

1 Like

@nasirs, got it - the update with Nethereum has an unsafe code block due to a utility (SCrypt.cs) that processes unit256 values. Did you originally pull from the development branch or load Nethereum dlls? I was testing the new release and ran into the issue.

Open build Settings->Player Settings and scroll down. Under Script compilation, check the box for ā€œAllow Unsafe Codeā€ Hopefully that will fix the issue for you.

Regards,

David

@nasirs, @SamR, @vivraan, @cuongnm, @jlourie, @YosephKS, @enoonmai, @K00N

Release 1.0.3 has been released. This included Nethereum integration and a bunch of other updates. Please re-read the README file, especially the part about importing and running the demo.

Regards,

David

6 Likes

Hi David, seems to work ok, I had some windows defense blockers that were getting in the way of some of the functionality I think as well. Thanks for your help, I will let you know if there are any other issues

How do you see this SDK working with VR and Oculus. do you see any potential compatibility issues with packages like OpenXR, XR Toolkit or Oculus Integration? I have tested them all out only thing I had to do so far was rename/delete the Player-Controller in the example package, have not tried to connect to Moralis yet though. Would the wallet connect just pop up on your phone in an android build/with Oculus. Or would it have to be in Steam VR. Just trying to work out how it would work functionally?

Thanks again for the help, this package was super needed

1 Like

Just read through the changes and am very excited for whatā€™s in this release. Will try it out ASAP.

1 Like

Some small issues that I have noticed:

  • Missing dependency for UnityEngine.InputSystem from the Lean UI stuff in Examples when importing to a new project (Deleting example folder fixes it though)
  • Deleting the Examples folder doesnā€™t seem to cause any problems :slight_smile:
  • WalletConnect prefab could go in MoralisWeb3ApiSdk/Prefabs? Seems like a handy prefab that isinā€™t just example related
  • There were a few .bak and .bak.meta files committed (could add that pattern to the .gitignore)
  • The ā€œAssetsā€ and ā€œAssets.Scriptsā€ namespaces seem like a pretty generic name, might be better to name the something more ā€œMoralisā€-related
  • Moralis Mug NFT contract on mumbai is not verified
2 Likes

Hi @dgoodrich
I still get error response when try to call clound function from client (MoralisInterface.GetClient().Cloud.RunAsync). The error is: Error: HTTP/1.1 400 Bad Request
{ā€œcodeā€:142,ā€œerrorā€:ā€œValidation failed. Please login to continue.ā€}

I build my app on WebGL platform.
Could you take a look on it?

2 Likes

Great suggestions. On this oneā€¦ Upvote +1

1 Like

@dgoodrich I updated a private demo to Moralis / Unity3D Asset Package v1.0.3

All working well except I noticed a bug and now my custom code works only after a workaround. Note that ā€œCustomā€ means I wrote it myself.

// Execute
MoralisClient moralisClient = MoralisInterface.GetClient();
MoralisQuery<Hero> moralisQuery =  moralisClient.Query<Hero>().WhereEqualTo("Level", 15);

IEnumerable<Hero> result = await moralisQuery.FindAsync();
List<Hero> results = result.ToList();

// Display
if (results.Count > 0)
{
	Hero heroToDelete = results[0];
	
	// Included Method - Throws "NullReferenceException: Object reference not set to an instance of an object"
	//await moralisClient.DeleteAsync(heroToDelete);
	
	// Custom Method - Works!
	await moralisClient.DeleteAsync2(heroToDelete);
}

The source of ā€œMoralisClient.csā€ (modified by me) containsā€¦

//MoralisClient.cs - Included Method
public Task DeleteAsync<T>(T target) where T : MoralisObject
{
    return target.DeleteAsync();
}

//MoralisClient - Custom Method
public async Task DeleteAsync2<T> (T target) where T : MoralisObject
{
    await ServiceHub.ObjectService.DeleteAsync(target, GetCurrentUser().sessionToken);
}
1 Like

Hey @dgoodrich, any update on connection of webGL with Metamask directly without qr code/walletconnect? Is qr code the only way around it now?

1 Like

Any Update on Unity Sdk Importing Nft Mesh

1 Like

@dgoodrich and all!

Iā€™m having fun with Moralis / Unity3D Asset Package v1.0.3.

Made a demo that takes a Unity sprite, serializes and uses Moralis to store it on https://ipfs.io/.

Very cool. Here is a snippet. The Moralis stuff is shown. The serialization/ui stuff is hidden for brevity.

namespace RMC.MoralisExamples.Example09_Web3API_Storage	
{
	/// <summary>
	/// Example: Moralis Authentication
	/// </summary>
	public class Example09_Web3API_Storage : MonoBehaviour
	{
	
		//  Properties ------------------------------------
		public ExampleButton SaveImageExampleButton { get { return _exampleCanvas.Button01;}}
		public ExampleButton ClearImageExampleButton { get { return _exampleCanvas.Button02;}}
		public ExampleButton LoadImageExampleButton { get { return _exampleCanvas.Button03;}}
		
		//  Fields ----------------------------------------
		[SerializeField] 
		private ExampleCanvas _exampleCanvas = null;
		
		[SerializeField] 
		private ExampleConfiguration _exampleConfiguration = null;

		[SerializeField] 
		private ExamplePanel _panelForSpriteDestination = null;

		[SerializeField] 
		private Sprite _spriteToSave = null;
		
		private Sprite _spriteDestination = null;
		private List<IpfsFile> _lastLoadedIpfsFiles = new List<IpfsFile>();
		private Image _imageDestination = null;
		
		//  Unity Methods ---------------------------------
		protected async void Start()
		{
			await SetupMoralis();
			await RefreshUI();
		}

		//  General Methods -------------------------------	
		private async Task SetupMoralis()
		{
			await MoralisInterface.Initialize(
				_exampleConfiguration.ExampleData.MoralisApplicationId,
				_exampleConfiguration.ExampleData.MoralisServerURI,
				_exampleConfiguration.ExampleData.HostManifestData,
				_exampleConfiguration.ExampleData.ClientMeta,
				_exampleConfiguration.ExampleData.Web3RpcNodeUrl);

			if (!MoralisInterface.IsLoggedIn())
			{
                                //TODO: Make custom, polished login/auth functionality
				Debug.Log("User is NOT logged in. Fix.");
			}

			//
			SaveImageExampleButton.Text.text = $"Save Image\n(Ipfs)";
			SaveImageExampleButton.Button.onClick.AddListener(SaveImageExampleButton_OnClicked);

			ClearImageExampleButton.Text.text = $"Clear Image\n(Ipfs)";
			ClearImageExampleButton.Button.onClick.AddListener(ClearImageExampleButton_OnClicked);
			
			LoadImageExampleButton.Text.text = $"Load Image\n(Ipfs)";
			LoadImageExampleButton.Button.onClick.AddListener(LoadImageExampleButton_OnClicked);

			// Dynamically add an Image to the existing UI to hold the loaded Sprite
			_imageDestination = ExampleHelper.CreateNewImageUnderParent(_panelForSpriteDestination.transform.parent);
		ExampleHelper.CanvasGroupSetIsVisible(_imageDestination.GetComponent<CanvasGroup>(), false);
			
			await RefreshUI();
		}

		private async Task RefreshUI()
		{
			_exampleCanvas.PageHeaderText.text = "Moralis - Web3API Storage";
			
			// Code Hidden For Brevity...
		}

		private void SaveContentStringToIpfs(string content)
		{
			// Define file information.
			IpfsFileRequest ipfsFileRequest = new IpfsFileRequest()
			{
				Path = "moralis/ipfsFileRequest.png",
				Content = content
			};
			
			// Multiple requests can be sent via a List so define the request list.
			List<IpfsFileRequest> ipfsFileRequests = new List<IpfsFileRequest>();
			ipfsFileRequests.Add(ipfsFileRequest);

			MoralisClient moralisClient = MoralisInterface.GetClient();
			_lastLoadedIpfsFiles = moralisClient.Web3Api.Storage.UploadFolder(ipfsFileRequests);
			
		}
		
		//  Event Handlers --------------------------------
		private async void ClearImageExampleButton_OnClicked()
		{
			string content = ""; //empty string means empty image
			SaveContentStringToIpfs(content);
			LoadImageExampleButton_OnClicked();
		}

		private async void SaveImageExampleButton_OnClicked()
		{
			string content = ExampleHelper.ConvertSpriteToContentString(_spriteToSave);
			SaveContentStringToIpfs(content);
			LoadImageExampleButton_OnClicked();
		}
		
		private async void LoadImageExampleButton_OnClicked()
		{
			if (_lastLoadedIpfsFiles.Count >= 1 && _lastLoadedIpfsFiles[0].Path.Length > 0)
			{
				Debug.Log("_lastLoadedIpfsFiles[0].Path: " + _lastLoadedIpfsFiles[0].Path);
				_spriteDestination = await ExampleHelper.CreateSpriteFromImageUrl(_lastLoadedIpfsFiles[0].Path);
				_imageDestination.sprite = _spriteDestination;
				ExampleHelper.CanvasGroupSetIsVisible(_imageDestination.GetComponent<CanvasGroup>(), true);
				await RefreshUI();
			}
		}
	}
}

3 Likes

@dgoodrich The MoralisInterface.GetClient().Web3Api.Storage.UploadFolder(ipfsFileRequests); method is synchronous, but it takes async time to execute. I suggest it be changed to an asynchronous method. Thoughts?

1 Like

You are on the same track as me this weekend. I am using a Quest2 and have been wondering the same thing about the wallet. I will post back when I know more - please share your experience as well!

BTW have you claimed your NFT?

Hmm. about the .bak I had that fixed, wonder if I munged my gitignore, will check.

Not sure why Lean would be missing something did you load from the package or the repo - I need to check it out

@enoonmai and @SamR,

I am in the process of creating a github repo that is strictly SDK and then keeping the current repo but adding a set of scenes with assets instead of trying to throw everything in the single example.

I want the SDK repo to be bare bones Moralis, so technically, everything above the Moralis folder can go. However, if I want the Web3 aspect, which is rather important, I have to have Wallet Connect and Nethereum as I do not have much choice as to what is available. These are tightly coupled only in the Moralis / Unity specific tools that are above the Moralis folder.

Maybe add a third repo that is a pure boiler plate with Moralis, W.C., Nethereum with an empty scene that has the current MoralisSetup and WalletConnect objects but nothing else.

As users of the tool do you have any thoughts on what to keep and what not to keep in the SDK repo?

Thank you,

David

1 Like

Make sure to read the documentation on Cloud Functions and validation and make sure you are including the required fields of the Cloud function (check spelling). If userRequired is set to true make sure your user is logged in before calling the cloud function.

If nothing above fixes the issue try this: in MoralisDotNet \ Platform \ MoralisCloud.cs, line 25, change ā€œuser.SessionTokenā€ to ā€œuser.sessionTokenā€

Make the same change in Moralis.WebGL \ MoralisDotNet \ Platform \ MoralisCloud.cs.

If this fixes your issue let me know, it means I missed something when I applied the fix for this to the WebGL part of the code.

Thank you,

David

1 Like