Documentation
Learn everything about the Theta Network.

Smart Contract Deployment Example

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

Before diving into the example, we would like to remind the readers that one can also deploy and interact with the smart contract via the Theta Blockchain SDK. Also note that on the Theta Blockchain, 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.

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.

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

Next, open your Theta wallet or create a new one. Once you’re logged in, select the Contract tab 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).

Updated 5 months ago



Smart Contract Deployment Example


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.