Alas, truebit-os has finally been released to the public to use and play around with. We still have a long journey ahead of us, but we are proud of the work that has been done up to this point. We often get the question, ‘How do I use Truebit for my project X?’, and this article is meant to be a detailed response to that question. This article describes at a high level the process of running a task on Truebit.

Since it might have been a while since you read the whitepaper, I’ll give a refresher on what Truebit does and how some parts of it work. Let’s start with an example. Imagine a developer building the next big thing on top of Ethereum. But oh no, their magical cryptographic algorithm exceeds the block gas limit. What on earth are they going to do? One option they have is to run the algorithm in the form of a Truebit task. In order to do this, a few things need to happen. The first and most important is how input data is expected to be provided. In order to input and output any kind of data with Truebit you have to go through Truebit’s Filesystem.

Truebit currently supports two types of storage, on-chain storage and IPFS. The on-chain storage works by deploying the data as a smart contract. The data is then accessed by simply passing around the contract address. This is secure, but expensive, and does not scale well. IPFS, is maybe less secure, because of the data availability problem (which is too large of an issue to get into right now), but scales very well. You can use either storage type and access that data in your program (task) as if it was a local file. So before you decide if Truebit is right for you, make sure to take into account all of your needed IO operations and how secure you want those to be. Effective storage is a very big concern of ours and we are actively looking into ways to improve this process for our users.

The next thing you have to figure out is how to write your program in some form that can be compiled into WASM. Truebit uses WASM because it is quickly becoming the platform to target. The WASM spec is also concise and focused. This makes implementing the WASM interpreter in Solidity simpler, and something we only need to do once. WASM is still new so there are a constraints around which program languages can be used. Garbage collected languages are not very well supported (however, this seems to be changing). As of writing this article, Truebit ONLY SUPPORTS TASKS WRITTEN IN C, C++, or RUST. We do not support running smart contracts in Solidity. Which is a common misunderstanding.

New technologies can come with their own growing pains. WASM compilers are no exception. You will be happy to hear that the truebit-toolchain was specifically designed to make the compilation process easier for developers. I won’t go into the details on how to use it here, because this is well documented in this post https://medium.com/truebit/truebit-toolchain-transmute-4984928364a7

Once you have a nice wasm file to execute, you’ll need an instance of truebit-os running. You can find detailed installation instructions here https://github.com/TrueBitFoundation/truebit-os. Once you have the client running you have everything you need to run a Truebit task. I’ll go over some more concepts to highlight how the process works. If you want to see a detailed example application, check out this repo https://github.com/TrueBitFoundation/example-app.

A lot of tasks require some kind of input and output. If you want a task to get input, you must read it from a file, and if you want the task to create some kind of output, you must write it to a file. How that data is accessed is dependent on the storage type chosen. In regards to the task, you simply use the standard IO operations of whatever language you are using. For the most part, everything else is automated for you by the truebit-os client.

Now that we have covered installation and compilation steps, I’m sure you are wondering how do I actually submit a task to Truebit to be solved? All task giver’s have to do is call createTask on our IncentiveLayer contract. Figuring out what arguments to put in this function is the hurdle to jump over. The basic createTask method of the Truebit contract, takes a few arguments:

initHash: You’ll need the initial hash of the task, so there is a deterministic starting point of the task. We are working on making this easier to do. codeType: 0 is WAST, 1 is WASM. You’ll know by your file extension of the task. storageType: 0 is Blockchain, 1 is IPFS. IPFS is cheaper. storageAddress: Contract Address or IPFS hash maxDifficulty: Determines the difficulty of the task (1 is okay for testing) reward: The amount of TRU tokens offered as a reward

If you have these parameters figured out then you’re ready to go. If you are expecting output data there might be some extra steps in dealing with the Truebit Filesystem, but that is a case by case basis. The example-app linked above demonstrates one way to do it. As a task giver, there is nothing more to worry about after submitting the task.

Hopefully, this answered a few questions you had about developing with Truebit. Please stay tuned for any updates. Our development team is working very hard to streamline this process and make developing on Truebit as easy as possible. This product is currently in beta form so please be patient. If you have any issues post them on our Github or ask for help on our Gitter https://gitter.im/TrueBitFoundation/Lobby