Integrating Unity and an Ethereum Node Using Nethereum
Intro to Nethereum
Nethereum is a library that facilitates the use of JSON RPC offered in an Ethereum Client, such as Geth or Parity, in C#. This can also be considered a C# version of the Web3 library, offered in JavaScript.
Nethereum’s Unity Support
If you visit the Nethereum library’s web page, it indicates that it supports Unity. With this library, one can use Ethereum in a mobile game developed on the Unity platform. It is even possible to take advantage of Ethereum’s Smart Contract. If you are planning on making a game that is more complex than Crypto Kitties, then I suggest you use Unity with the Nethereum library.
Sounds great, but using Nethereum in Unity is not a seamless process. This is because Unity uses a low version of .Net. Thus, it is not possible to use many enticing API offered by Nethereum. You must use the API offered separately for Unity only. Furthermore, there are problems in the documentation itself. The documents only provide information about environments not related to Unity. Thus, trying to use Nethereum in Unity after reading the documentation is a huge pain for the developer. The functions specified in the official documentation cannot be used in Unity.
Going forward, I shall discuss my own experiences in using Nethereum in conjunction with Unity.
Downloading Library for Unity
https://github.com/Nethereum/Nethereum/releases
You must download Nethereum.Unity.zip from GitHub’s release page. If you get the library through other methods, such as nuget, then it will not work with Unity.
How to Use
Usually, when using the library for the first time, you would check out the official documentation. Then you would probably follow the tutorial offered in that documentation. However, in Nethereum, there is no official documentation on how to use it in Unity. Although there is nothing official, there is a blog that gives us a simple explanation on how to use this library.
Nethereum 2.0.0 rc5 — Unity3d integration
Functions Offered by the Library
Nethereum that is distributed for Unity purposes have the following functionalities:
- Web3’s APIs
- There are functions in the Nethereum.JsonRpc.UnityClient namespace that correspond 1:1 with web3’s API. For instance, one can acquire the Account’s balance, send a Transaction, call the Contract, etc.
- Create a private key, and sign.
- Allows the creation of an Ethereum account or signing of arbitrary data by using the functions of EthECKey that is under the Nethereum.Signer namespace.
- Sign offline.
- By using TransactionSignedUnityRequest, one can sign the transaction within the game before sending. With this functionality, the user’s private key does not need to be send to the Ethereum node, and can be managed in the game itself. (For more information, please check this link.)
Conclusion
Nethereum provides many useful functionalities. However, there is insufficient information and documentation for the Unity game engine. I hope this short article will be helpful in making your own game that is interlocked with Ethereum. (For the Korean version of this article, click here.)
Last but not the least! Now it’s time to enjoy GoCryptobot.
Download from here :)
- App Store: https://apple.co/2KbMipn
- Google Play: https://bit.ly/2K5tYhx