Announcing THETA Smart Contracts Sandbox Launching on Testnet

Theta Labs
Theta Network
Published in
6 min readMay 21, 2020

While we’re all very focused and excited about the upcoming release of Theta Mainnet 2.0 in just 6 days on May 27, the Theta development team has also been hard at work on smart contract functionality for Theta blockchain originally slated for the second half of the year. We’re happy to announce smart contracts are now ready for release in alpha today, on a new Theta testnet created specifically for this — the Theta Smart Contract Sandbox!

As you probably know, the smart contract platform space is very crowded, and building a new developer community from scratch is nearly impossible. So with that in mind, we wanted to make developing on Theta as easy as possible for Ethereum developers, since they number the largest in blockchain by far (according to Consensys, more than 200,000 active developers). To that end, smart contracts on Theta are fully compatible with the Ethereum Virtual Machine. This means that essentially ANY Ethereum smart contract can be easily ported over to run on Theta blockchain, and any blockchain developer that works in Solidity can jump right in developing brand new smart contracts on Theta as well.

The most immediate benefit to adding smart contracts to Theta is that video platforms integrating Theta now have more tools to implement their business models. For example, on THETA.tv when users donate TFUEL to their favorite streamers, it could be stored in a smart contract until a certain threshold is hit and it’s passed through to the streamer — think like reaching a Kickstarter goal, but automatically enforced via smart contract! Or a smart TV operator or mobile handset manufacturer could incentivize users to relay specific content over Theta Network by storing extra TFUEL in a smart contract, which is unlocked when a user relays a certain amount of video over Theta Network. The possibilities are endless! Just as the creators of Ethereum did not conceive of DeFi when Ethereum was first created, we think the most valuable Theta smart contracts and dapps will likely come from emergent development from the Theta community, in use cases perhaps we haven’t even considered yet.

How do I get started?

While this is an alpha release and there are still many tools needed to make contract creation more convenient for devs, in this release there is already a command line and GUI/wallet based smart contract deployment and interaction.

For CLI command info: https://github.com/thetatoken/theta-protocol-ledger#deploy-and-execute-smart-contracts

If you prefer to work with a graphical interface, the beta Theta web wallet now includes a Contracts section where you can deploy and interact with smart contracts: https://wallet-beta.thetatoken.org/

Smart Contract Sandbox block explorer: https://smart-contracts-sandbox-explorer.thetatoken.org/

In this implementation, TFUEL takes the place of ETH in all contracts. Just as you need ETH to deploy or interact with smart contracts on Ethereum, you need TFUEL to do so on Theta blockchain. All TFUEL used to deploy or interact with smart contracts is burned. If you want to try it out, just email your testnet address to support@thetatoken.org and we’ll send you 100 TFUEL on the Smart Contract testnet to get started. (A testnet TFUEL faucet is also in the works, so soon users can just get this TFUEL themselves automatically. Or if you are running a GN on testnet already, just ping a Theta team member in Slack!)

A quick smart contract example, deployed using the Theta web wallet

Let’s do a quick walkthrough of how to deploy a smart contract on Theta testnet! We’ll make a limited edition token on top of Theta blockchain to denote the early adopters of Theta protocol — the Theta supporters who have run Guardian Nodes on the Theta testnet.

We can start with a basic token smart contract, found here on Theta GitHub.

To compile this Solidity code, we can use the Remix Ethereum compiler. (Another benefit of using an Ethereum-compatible VM for Theta — much of the extensive Ethereum dev tools can be used here as well.)

We’ll walk through this process step by step, but for more in-depth instructions on using Remix, see the documentation here.

Next, create a new file in Remix called “OriginalGN.sol” and copy/paste the code from the example on Theta GitHub. Once the code is entered, click the Solidity Compiler button on the far left.

Next, you’ll want to set the Compiler to “0.4.16+commit.d7661dd9”, and in the Contract field “OriginalGN” is selected. Then click the blue button that says “Compile OriginalGN.sol”.

Your smart contract is now compiled! Now for the moment let’s go over to the beta Theta wallet. From the dropdown menu at the top, select “Smart Contracts Sandbox” to join the appropriate testnet. Then, open your Theta wallet or create a new one.

Once you’re logged in and you’ve received Smart Contracts Sandbox testnet TFUEL (by emailing support@thetatoken.org or asking a Theta team member in Slack), select Contract from the wallet menu.

The Contract screen will ask you for two outputs from your compiled smart contract: the ABI/JSON Interface, and the Byte Code. Go back to Remix, and you can copy both by clicking the buttons “ABI” and “Bytecode” under the “Compilation Details” button. Then, paste each into the Theta wallet and click “Deploy Contract”.

Your contract is now live on the Theta Smart Contracts Sandbox! Make sure to record your contract address.

Now you can try out the different functions for this contract, for example:

totalSupply: returns 433, the max number: one for each of the original tesnet Guardian Node users!

symbol: returns OGN, the token’s symbol

transfer: Allows you to transfer the 433 tokens to other addresses on the Smart Contract testnet.

balanceOf: Once you’ve sent tokens to another address, you can use this function to check that they’ve arrived.

Other users can sign in to the Smart Contracts Sandbox and interact with your smart contract as well. They will need to know both the contract address and the ABI/JSON interface data. That’s a bit unwieldy, but an example of one of the ease-of-use improvements that will come with future versions of the Theta smart contract interface (for example, that ABI data could be made to auto-populate when a given smart contract address is entered).

What’s next?

While this is an early build of Theta smart contract functionality, we are very excited for this alpha release! For those in the Theta community who know how to program smart contracts, we can’t wait to see what you have in store for Theta development. It’s not too early to get started, since any smart contracts built on testnet will port over to Theta Mainnet 2.0 once smart contract functionality is enabled later this year, after further testing and building out of developer tools.

On that note, the Theta Hackathon on DevPost will be extended to allow more time for developers given this new release, so we’ll see who earns the $10,000 first prize! Smart contracts developed for Theta testnet WILL be considered if they actively incorporate a use case for Theta.

Any questions? Don’t hesitate to reach out to us at support@thetatoken.org. And we’ll see you next week for the launch of Theta Mainnet 2.0!

Cheers,

the Theta team

--

--

Theta Labs
Theta Network

Creators of the Theta Network and EdgeCloud AI — see www.ThetaLabs.org for more info!