Stratis Platform
Stratis Ltd. is the creator of Stratis Platform, a blockchain technology platform for enterprises to build enterprise-grade blockchain-based solutions using Microsoft’s .NET framework and C# language. Stratis Platform is easy to learn, adapt, and integrate with existing enterprise applications. Stratis offers both public blockchain and private blockchain solutions. Stratis’s product offerings include Distributed Ledger Technology (DLT), Identity Platform, Supply Trust, STO Platform, DiFi, and Smart Contracts written in C# and executed on native .NET CLR makes it appealing to companies that want to build blockchain solutions on Microsoft stack.
Visit here to learn more about Stratis Platform.
Blockchain
A blockchain is a growing list of records, known as blocks, that are cryptographically linked together. A cryptographic hash of the preceding block, a timestamp, and transaction data are all included in each block (generally represented as a Merkle tree). To get into the hash, the timestamp validates that the transaction data existed when the block was published. Each additional brick reinforces the ones before it, forming a chain.
To know more about Blockchain, visit the C# Corner Blockchain category.
Stratis Unity 3D SDK
Developed by Unity Technologies, Unity is a cross-platform game engine with a built-in IDE and is used to create video games for web plugins, consoles, desktop platforms, and mobile devices.
Stratis Unity SDK allows the STRAX Token to be used in game creation as well as the InterFlux Hub, opening up a world of possibilities through Stratis’ Smart Contracts written in C#.
Non-Fungible Tokens (NFTs) are of special relevance to game developers that want to include in-game currency. By implementing an NFT, in-game things can be truly held by the player, eliminating the possibility of losing acquired things due to lost login credentials or account termination.
Blockchain is a perfect fit for gaming, and now that blockchain and cryptos have hit the mainstream, platforms like the one Stratis just introduced are likely to attract a substantial number of developers. In addition, some of the earliest opposition that cryptos found was due to the fact that they are a form of digital money that competes with fiat currency.
Stratis Blockchain Technologies’ expanded Unity 3D support to include a light wallet and SDK for Stratis Blockchain Technologies. This achievement enables both the STRAX Token to be supported within game development and the InterFlux Hub, enabling endless use-cases through the utilization of Stratis Smart Contracts in C#.
Pre-Requisites
- Download and install .NET Core SDK 3.1: visit here
- Download and install Git: visit here
Cloning the Stratis Full Node source.
First, you must obtain a local copy of the Stratis Full Node; this can be achieved by using the git clone command.
For the purpose of this document, we will be using the desktop as the root directory.
Execute the below command: git clone visit here
The above command will clone the source code to the below directory,
C:\Users\Admin\Desktop\StratisFullNode
.NET Downloads (Linux, macOS, and Windows) visit here
Git - Downloads: visit here
Download the Stratis Unity Package from here Then the next page will open, then click go-to site, then the unity package will be downloaded.
So the first thing that you're gonna do is to set up a Stratis node on a server with a static IP address. For that, we need to clone the repository.
You can clone using the following command,
git clone https://github.com/stratisproject/StratisFullNode.git
It's cloned now so let's go to the source and let's build it. In order to build it, you need to install the .Net SDK and 3.1.net core SDK and build it for the release using the command
dotnet build
When we've built it we can start it. I'm gonna start it on Stratis mainnet. Basically, I'm running Stratis daemon DLL and we need to supply the following line arguments, copy the below command and run in Powershell.
dotnet exec .\Stratis.StraxD.dll -txindex=1 -addressindex=1 -unityapi_enable=true -unityapi_apiuri=http://0.0.0.0
We need to enable transaction index and address indexing, and then enable unity API also, you need to run it on this IP address or IP of your choice.
Once we execute the command, a local version of Stratis FullNode will start running and syncing with the mainnet.
While it's syncing we can open the port in the firewall, as we want to allow inbound and outbound ports.
So basically you need to create Inbound and Outbound rules for a port on which you want to run Unity 3D API. The default port for unity API is 44336, but you can specify what you want.
Given below are some of the arguments which can be provided to modify the Unity 3D API feature.
Now let's check if it works, so first let's go to swagger on localhost:44336.
Note: The node can take some time depending on the internet speed, to get fully synced.
Make sure you have a completely synched node,
So now let's go and run unity and try to connect to our API.
Prerequisites
- Unity Environment version 2018.4.25f1
Create the project
Now we have a new unity project and let's import our unity package, click import.
Now once it's imported we can open an example thing.
Run the example scene. It is a simple UI that you can use to test the solution, first, we will need to provide the correct endpoint and in my case, "http://localhost:44336" is the IP address, so if you've set up everything properly, click test.
You will see that the API test was successful.
So what we can do after this is to generate a new mnemonic and once you are done, click on generate. You can also just use your old mnemonic in case you already have a wallet created in unity.
Click on "Initialize" and here is your address to which you can deposit STRAX. Let's copy it and now let's go back to our swagger API server. I have a default wallet that I have prepared here which has (0.1) STRAX.
So let's send some STRAX from this wallet. We will go to normal node API and used build transaction endpoint so here it.
Let's deposit 0.1 Stratis coins to our address and click on execute button.
Copy the hex text generated.
Now we have hex and we can use it to send transactions.
You can also just use a normal UI wallet to deposit to that address but I,m doing it this way so we can see that now we have some unconfirmed balance.
Now if we go back to unity and refresh our balance we can see that we have some money here.
Let's send some transactions to basically any address.
We can send two types of transactions, one is a normal transaction where you supply the destination address and the amount you want to send, and the second is an op return transaction which basically allows you to encode any data and post it to the blockchain. So let's try both of those. Let's say I deposited 0.0505 to an address.
Now we can see the transaction was created and we get the transaction id, based on which we can explore about the transaction on Stratis explorer.
Let's open this address in the explorer and see if any transaction was created, so it will take some time for the transaction to be mined before it will appear. Typically it will be less than half a minute, so let's wait.
Once the transaction shows up, click on the transaction to see the transaction details.
Now we will do the second type of transaction, which is encoding any operator and data. So let's put any data here and click send.
Then again open Stratis explorer and look for this address, once the transaction is confirmed and we can see the transaction details, if we open it that we have one output op return and it has our data encoded there.
So that's pretty much it, another example that you can look into is an example without UI. if you open game object name scripts here is an example with UI disabled.
We can open it in visual studio and here is basically code that calls every API method available on unity 3d API and also how to send normal transactions and how to send op return transactions, it's pretty simple and self-explanatory so check it out.
Summary
I hope you understood how to Integrate Stratis Blockchain in Unity Game.
Visit here to learn what is blockchain.
You can visit the Unity SDK for Stratis Blockchain Technologies