Getting started with Loom, Truffle and Unity

Zac Holland
4 min readJun 20, 2018

My goal for the next few weeks is to create a blockchain game using Loom. The best stack in my mind would be to use Truffle for contract development and Unity to flesh out the client.

I just spent the last 8 hours trying to figure all of this out. I got a ton of help from their team and the Loom community, and I’ve decided to log my progress here in hopes of this being the last time someone has to struggle with this.

Step 1: Install Loom

This part’s easy. Just follow the tutorial here for your operating system. Once it’s installed just start it up.

They also have a few Docker containers that they keep up to date. The links to them are at the bottom of this page.

Step 2: Set Up Your Project

My project looks like this

Step 3: Set Up Truffle in the dappchain Folder

In the dappchain folder I’ve followed this short tutorial to get a barebones truffle project set up.

Just go in there and run yarn deploy to get your contracts up onto your loom chain.

NOTE: If deploying doesn’t work or is giving you errors, there’s a couple things that could be wrong!

  1. It might not be able to connect to your Loom node. If you’re running it on another computer or on a VM make sure the IP is set correctly in truffle.js or truffle-config.js
  2. Some Truffle and Solc versions don’t play nice with Loom. Make sure Truffle is on v4.1.8 and Solc is on v0.4.23

Step 4: Set Up Your Unity Project in unityclient Folder

In the unityclient folder I grabbed the Unity 3D SDK and just threw it in (they don’t have a Unity package available yet).

Step 5: Tell Truffle to Export Your ABIs and Addresses

First, go into your Unity project and create the directories Assets/Resources/contracts/abi and Assets/Resources/contracts/address

These folders are where your contract data is going to be exported.

Now back in your Truffle project, add a file in your migrations folder called 99_export_abis.js Your project should look something like this now

Every step in your migrations folder get’s called when you migrate/deploy and 99 will make it the last step. Here’s what they should look like:

These will work assuming you’re project is set up exactly the same as mine. If you changed any of the names, make sure you update the paths in the code above.

Also, make sure you run yarn deploy or yarn deploy:reset to make sure these ABIs and Address files get put into your Unity project’s directory.

Step 6: Set Up Your Unity Scene

Go ahead and create a new scene, and in that new scene create an empty game object with a new script called SimpleStoreHandler attached. Should look like this:

And here’s what should be in your SimpleStoreHandler script

It’s all pretty well commented, but if you have any questions about it let me know!

Conclusion: Testing

Try running the Unity project! You should see a few messages and some data coming in from Loom!

If you run into any problems let me know! I’ll be adding any other hitches other people run into and tell me about. Hopefully this setup process doesn’t have to be as daunting!

Edit: Troubleshooting some errors

Exception: JSON-RPC Error -32603 (Internal error): name is not registered

If you get this error in Unity, it means you’re trying to access your contract by name when you should be accessing it by it’s address. Only Go-Loom plugins can be accessed by names, Solidity EVM contracts need to be accessed by address. All you have to do here is get the address of you contract and use the code in Step 6 line 58 to instantiate an EvmContract class with your address.

Source Code

ETH Tip Jar!

0xACc0E804ED005A8be4A95Bdb03DBa13337183738

--

--

Zac Holland

Software engineer, love helping others and learning as much as possible