How to create EOS Token

Creating Eos Token using eosio.token Contract

CUBE
Coinmonks
Published in
5 min readJul 23, 2018

--

In EOS, tokens can be published simply by using the eosio.token contract. The eosio.token contract is stored in the Contract directory at the time of EOS installation. Token contracts with different functions can also be configured separately by referring to eosio.token.

In this post, we will publish a token using the eosio.token contract.

Create User Account

Create a user account before publishing. Users will use usersc, user1, user2; I’ll skip creating the user account part (but I find myself describing it anyways as I write…).

First, to proceed in the order of developer eosio, create an eosio.token account.

#cleos create key

Generate the two keys.

#cleos wallet import [Private Key]

Save the key onto the primary wallet.

#cleos create account eosio eosio.token [Public Key]

Create the eosio.token account using the generated key.

#cleos set contract eosio.token ~/eos/build/contract/eosio.token -p eosio.token

Deploy the eosio token contract, which is the primary contract for creating, issuing and transferring tokens. The eosio token contract is located in the [eos source] /build/contracts/eosio.token directory.

Token Generation

Now that we’re ready, let’s generate a token.

#cleos push action eosio.token create ‘[“eosio”,”1000000000000.000 SYS”]’ -p eosio.token

Create a ‘SYS’ token using the create action of the eosio.token contract. The first data transmitted to the action is the issuer, and, in this example, is the system-owned account, eosio. The second data is the maximum quantity that can be supplied, in this example set at one trillion.

Issue the generated token to the user. In this post, 100.0000 SYS was published to user1.

#cleos push action eosio.token issue ‘[“user1”,”100.0000 SYS”,”memo”]’ -p eosio

When publishing, you must execute using the eosio account privilege. Otherwise, you will get a message that you do not have the appropriate permission, as above. Also, if you look closely at the output, an issue consists of a transaction with several actions.

#cleos get currency balance eosio.token user1

Check the balance of user1 with a simple command.

#cleos push action eosio.token transfer ‘{“from”:”user1”,”to”:”user2”,”quantity”:”10.0000 SYS”,”memo”:”memo”}’ -p user1

User1 now passes 10.0000 SYS to user2. Of course, this needs to be done using user1’s account.

#cleos get currency balance eosio.token [username]

Check each balance.

Up until now was a basic eosio token contract example. Now, we will test more about how the eosio token contract works.

Operation Test

First, is the question of if eosio.token contract is able to control other tokens than ‘SYS’.

#cleos push action eosio.token create ‘[“eosio”,”10000000000000.0000 TST”]’ -p eosio.token

It probably won’t work, but let’s try creating a new token called ‘TST’.

#cleos push action eosio.token issue ‘[“user1”,”1000.0000 TST”,”memo”]’ -p eosio

Issue 1000.0000 TST to user1.

Now user1 has two types of tokens.

Second, as we already know, the eosio token contract is the result of compiling the source code. Then the next question is if it possible to run the eosio token contract with another account?

#cleos set contract usersc ~/eos/build/contracts/eosio.token -p usersc

Deploy the eosio token contract to usersc account. Successful.

#cleos push action usersc create ‘[“eosio”,”1000000000000.0000 TSA”]’ -p usersc
#cleos push action usersc issue ‘[“user1”,”1000.0000 TSA”,”memo”]’ -p eosio

Generate a token TSA and issues it to user1. As always, if you are publishing a token, you need the system account for nodeos.

You can view all balances by referring to the usersc contract account to check balances.

Third, what would happen if you overwrite another contract over usersc in the above situation?

#cleos set contract usersc ~/sc/helloworld/ -p usersc

Deploy a simple helloworld contract.

Interestingly, the contract itself is gone, but the search fails if you search the table to see if the balance remains. The balance information also disappears as the existing table is deleted.

However, if you redeploy the usersc eosio.token contract and look up the balance

#cleos set contract usersc ~/eos/build/contracts/eosio.token -p usersc#cleos get currency balance usersc user1

The existing balance is restored. In fact, rather than saying it’s restored, the table used by usersc was left as is, but the information about the contract that refers to the table has been lost as the contract changed.

If you conduct tests like this for eos token contracts, you will start to understand more the interaction between contracts and tables. This post described how to test the behavior of a contract in various ways after running the token generation example to let you know that there is a different direction than to start analyzing the source code in a way that explains how the token system works in eos.

ITAM Games is a blockchain platform for a transparent gaming ecosystem

Subscribe to ITAM Games and receive the latest info.

Visit the ITAM Games Telegram to communicate regarding ITAM Games and Blockchain. Join by clicking the link below! 👫

Website: https://itam.games
Telegram: https://t.me/itamgames

--

--