Below we show a quick Solidity smart contract example, compiled using Remix and deployed through the Theta web wallet.

In this example, we’ll make a limited edition TNT-20 token (ERC-20 equivalent, TNT stands for Theta Network 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.

1477

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.

1858

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.

1371

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”.

1437

Your smart contract is now compiled! Now for the moment let’s go over to the Theta wallet. If you want to do a production deployment, from the dropdown menu at the top, select “Mainnet". For test deployment, select “Smart Contracts Sandbox” instead (just email your wallet address to [email protected] and we’ll send you 100 TFUEL on the Smart Contract testnet). In this example, we'll deploy to the smart contract sandbox.

515

Next, open your Theta wallet or create a new one. Once you’re logged in, select the Contract tab from the wallet menu.

1160

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”.

1451

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

1465

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