Deploy TT20

Deploy Your Own TT20

ERC20 tokens are one of the most popular DApps in the blockchain community. This tutorial will guide you through deploying an TT20 smart contract on ThunderCore in 5 simple steps. It's super easy and fast!

Requirements

This tutorial expects you to have some basic knowledge of Truffle, Ethereum, Metamask and Solidity.

Install development tools

Please install the following:
1
Node.js v8+ LTS and npm (comes with Node)
2
Git
3
Yarn (optional)
Copied!
Once we have those installed, we only need one command to install Truffle:
1
npm install -g truffle
2
# or
3
yarn global add truffle
Copied!
To verify that Truffle is installed properly, type truffle version on a terminal.

Install MetaMask

MetaMask is a browser extension that serves as a “wallet” that safely stores your cryptocurrencies such as Ether (ETH) and ThunderCore (TT). It also serves as a “bridge” that connects the web application with the blockchain. You can download and learn more about Metamask.
Get ThunderCore (TT) or ThunderCore Testnet Tokens to get started, you will need to get Thunder Token (Mainnet) or Thunder Testnet Token (Testnet) to deploy your smart contracts on ThunderCore. Please follow this instruction to get your tokens.

Steps in this tutorial we will be covering:

  • Cloning tt20 repository and installing dependencies
  • Updating config file of TT20 Token
  • Compiling and deploying the smart contract on ThunderCore
  • Transfering your TT20 to others

1. Cloning TT20 repository and installing dependencies

To make it easier to get started with ThunderCore, we've created a ERC20 contract, TT20. You can download the contract with git command.​ On a terminal, input the following command to download the repository
git clone https://github.com/thundercore/tt20
Next, we'll update the required dependencies for deploying the contract.
1
npm install
2
# or
3
yarn install
Copied!

2. Updating config file of ERC20 Token

Since we've finished the contract already, the only thing we need to do is to update the config file config.json in tt20 folder. The config.json should look like the following:
1
{
2
"name": "SampleToken",
3
"symbol": "SPT",
4
"decimals": 9,
5
"initialSupply": 1.5e9
6
}
Copied!
Change these fields to whatever you want, for example:
1
{
2
"name": "MyToken",
3
"symbol": "MT",
4
"decimals": 8,
5
"initialSupply": 1.5e9
6
}
Copied!
Things to note:
  • The name and symbol fields give our token a unique identity.
  • The decimals field determines the degree to which this token can be subdivided.
  • The initialSupply field determines the number of tokens created when this contract is deployed. In this case, the number is arbitrary. Now, we have our own tokens!

3. Compiling and deploying the smart contract

In the migrations/2_deploy_contracts.js, we load the configuration from config.js of ERC20 and deploy the contract. Before we compile and deploy our own ERC20, we can setup a local chain. By using a local blockchain, we can test our contract without consuming real tokens. We recommend using Ganache. Refer to thundercore/ganache and build the Ganache GUI or using the CLI tool thundercore/ganache-cli with the following command.
1
# in tt20 repository
2
npm install -g thundercore/ganache-cli#tt
Copied!
After install the dependencies of ganache-cli, we can launch a local blockchain with the following command.
1
cd tt20
2
cd node_modules
3
cd / .bin
4
ganache-cli --networkId 5777 -p 9545
Copied!
With our blockchain launched, run the following command to compile and deploy the contract
1
# deploy Token contract to network 'development'
2
./deploy-contracts --network development
Copied!
You will see output that looks similar to this:
1
Command: [ 'truffle', 'migrate', '--network', 'development' ]
2
Compiling your contracts...
3
===========================
4
> Everything is up to date, there is nothing to compile.
5
6
7
Starting migrations...
8
======================
9
> Network name: 'development'
10
> Network id: 5777
11
> Block gas limit: 6721975 (0x6691b7)
12
13
14
1_initial_migration.js
15
======================
16
17
Replacing 'Migrations'
18
----------------------
19
> transaction hash: 0x604136ec8bb8d95a819f6f1c962c622583a9c6f2bf91a7616e9a137ab278c6a6
20
> Blocks: 0 Seconds: 0
21
> contract address: 0xeae24EB27F866225cF6f29370054F7470A94417F
22
> block number: 1
23
> block timestamp: 1628560607
24
> account: 0xa2b543E95EC730A61D40D1cCeb41C68aDe60072c
25
> balance: 99.9967579
26
> gas used: 162105 (0x27939)
27
> gas price: 20 gwei
28
> value sent: 0 ETH
29
> total cost: 0.0032421 ETH
30
31
32
> Saving migration to chain.
33
> Saving artifacts
34
-------------------------------------
35
> Total cost: 0.0032421 ETH
36
37
38
2_deploy_token.js
39
=================
40
41
Replacing 'Token'
42
-----------------
43
> transaction hash: 0x737c5536c25c44c9cd8a40a8a0c0b25986e2d3d49a4823ea52e7d15c30f66e87
44
> Blocks: 0 Seconds: 0
45
> contract address: 0x0A7e26D081ffbe772791fC312101210c495b4550
46
> block number: 3
47
> block timestamp: 1628560608
48
> account: 0xa2b543E95EC730A61D40D1cCeb41C68aDe60072c
49
> balance: 99.9608271
50
> gas used: 1739114 (0x1a896a)
51
> gas price: 20 gwei
52
> value sent: 0 ETH
53
> total cost: 0.03478228 ETH
54
55
56
> Saving migration to chain.
57
> Saving artifacts
58
-------------------------------------
59
> Total cost: 0.03478228 ETH
60
61
62
Summary
63
=======
64
> Total deployments: 2
65
> Final cost: 0.03802438 ETH
Copied!
Now, your MyToken is deployed and mint to your first address in ganache.
With our blockchain launched, run the following command to compile and deploy the contract.
1
# deploy Token contract to network 'development'
2
./deploy-contracts --network development
Copied!
You will see output that looks similar to this:
1
Command: [ 'truffle', 'migrate', '--network', 'development' ]
2
3
4
Compiling your contracts...
5
===========================
6
> Everything is up to date, there is nothing to compile.
7
8
9
Starting migrations...
10
======================
11
> Network name: 'development'
12
> Network id: 5777
13
> Block gas limit: 6721975 (0x6691b7)
14
15
16
1_initial_migration.js
17
======================
18
19
Replacing 'Migrations'
20
----------------------
21
> transaction hash: 0x604136ec8bb8d95a819f6f1c962c622583a9c6f2bf91a7616e9a137ab278c6a6
22
> Blocks: 0 Seconds: 0
23
> contract address: 0xeae24EB27F866225cF6f29370054F7470A94417F
24
> block number: 1
25
> block timestamp: 1628560607
26
> account: 0xa2b543E95EC730A61D40D1cCeb41C68aDe60072c
27
> balance: 99.9967579
28
> gas used: 162105 (0x27939)
29
> gas price: 20 gwei
30
> value sent: 0 ETH
31
> total cost: 0.0032421 ETH
32
33
34
> Saving migration to chain.
35
> Saving artifacts
36
-------------------------------------
37
> Total cost: 0.0032421 ETH
38
39
40
2_deploy_token.js
41
=================
42
43
Replacing 'Token'
44
-----------------
45
> transaction hash: 0x737c5536c25c44c9cd8a40a8a0c0b25986e2d3d49a4823ea52e7d15c30f66e87
46
> Blocks: 0 Seconds: 0
47
> contract address: 0x0A7e26D081ffbe772791fC312101210c495b4550
48
> block number: 3
49
> block timestamp: 1628560608
50
> account: 0xa2b543E95EC730A61D40D1cCeb41C68aDe60072c
51
> balance: 99.9608271
52
> gas used: 1739114 (0x1a896a)
53
> gas price: 20 gwei
54
> value sent: 0 ETH
55
> total cost: 0.03478228 ETH
56
57
58
> Saving migration to chain.
59
> Saving artifacts
60
-------------------------------------
61
> Total cost: 0.03478228 ETH
62
63
64
Summary
65
=======
66
> Total deployments: 2
67
> Final cost: 0.03802438 ETH
Copied!
Now, your MyToken is deployed and mint to your first address in ganache.

4. Deploy to the ThunderCore Testnet and Mainnet

Now, you can prepare to deploy your token to ThunderCore Testnet or Mainnet. Please make sure you have Thunder Testnet Token (TST) or Thunder Token (TT). First you set up the control of your account to truffle. You can set either by:
  • Write your 12-word mnemonic (seed phrase) to a file named .mnemonic
  • Export your account private keys, one per line, to a file named .private-keys
1
# If you use private keys
2
mv .private-keys.template .private-keys
3
4
# in .private-keys file, put your private keys
5
e59cb5e369b65eee650f90f3280cbe8039db81335943ac7a88df5f4df...
6
d92a96fa691a7c31b2e2891de05cacc85d562b128afa6bb8f7108aac7...
7
8
# If you prefer mnemonic
9
mv .mnemonic.template .mnemonic
10
11
# In .mnemonic file, put your mnemonic
12
dog cat apple bird ...
Copied!
  1. 1.
    If you use metamask to control your address, you can check how to export the private key here. The address you used will be filled your MyToken .
  2. 2.
    Compile and migrate your contract for Thunder Testnet and Thunder Mainnet
1
# Deploy to testnet
2
./deploy-contracts --network thunder-testnet
3
4
# or Deploy to mainnet
5
./deploy-contracts --network thunder-mainnet
Copied!
  1. 1.
    After deploying your own token, totalSupply will be added to your accounts. Check out MetaMask to see how to add custom token on MetaMask. The token contract address should be in the stdout after you executed the deployment command.
1
2_deploy_token.js
2
=================
3
4
Replacing 'Token'
5
-----------------
6
> transaction hash: 0x737c5536c25c44c9cd8a40a8a0c0b25986e2d3d49a4823ea52e7d15c30f66e87
7
> Blocks: 0 Seconds: 0
8
> contract address: 0x0A7e26D081ffbe772791fC312101210c495b4550
9
> block number: 3
10
> block timestamp: 1628560608
11
> account: 0xa2b543E95EC730A61D40D1cCeb41C68aDe60072c
12
> balance: 99.9608271
13
> gas used: 1739114 (0x1a896a)
14
> gas price: 20 gwei
15
> value sent: 0 ETH
16
> total cost: 0.03478228 ETH
17
18
19
> Saving migration to chain.
20
> Saving artifacts
21
-------------------------------------
22
> Total cost: 0.03478228 ETH
Copied!

5. Transferring your ERC20 token to others

If you have already added MyToken to your MetaMask, try to send your tokens to other accounts. See more detail on MetaMask doc Note If you try on your local ganache, make sure to set the custom network to your localchain. For exmaple, set rpc url to http://localhost:9545 and chain id 5777. Then you can import private key from ganache to metamask or open a browser without MetaMask (such as incognito window) to see your tokens. Learning more about DApps It’s beyond the scope of this tutorial to go over the code, but if you’d like to learn more about smart contract programming and building DApps in general, we recommend the official Solidity documentation and truffle tutorial. For questions, please join to our Discord channel. Happy Coding! 😆
Copy link