How to Create and Deploy Your Own EOS Token

Written by ylv | Published 2018/07/16
Tech Story Tags: ethereum | eos | token | eos-token | deploy-an-eos-token

TLDRvia the TL;DR App

We are going to figure out what is EOS token and how you can create and deploy one yourself.

Photo by Aleksey Shmatov

What is EOS Token?

EOS contrary to Ethereum comes with the token smart contract out of the box. As Ethereum has ERC20 smart contract, EOS has eosio.token smart contract. Eosio.token smart contract allows you to create your own token by providing maximum supply and token’s literal, issue tokens to an account and transfer tokens between accounts. EOS tokens on EOS blockchain are issued using the same contract.

The `url` parameter specifies to witch node you connect. You can checkout more API endpoints on the official website.

Install Cleos

Cleos is a command line tool that interfaces with the REST API exposed by nodeos. We need cleos to run all the commands to interact with EOS blockchain. You can install cleos using Docker, AWS Image or compiling the source code. The end result has to be cleos avaiable in your terminal.

Create Wallet

Wallets are clients that store keys that may or may not be associated with the permissions of one or more accounts. Ideally, a wallet has a locked (encrypted) and unlocked (decrypted) state that is protected by a high entropy password. The EOSIO/eos repository comes bundled with a command line interface client called cleos that interfaces with a lite-client called keosd and together, they demonstrate this pattern.

from ‘Accounts and Permissions

Let’s create one called ‘treasure’.

You have to save password somewhere safe, because if it is lost, there is no way to recover all the keys inside the wallet.

Now we need to generate two pairs of keys for the owner and active permissions. After that, we import them into our wallet.

Create Account

In order to do anything at EOS blockchain you need to have an account.

An account is a human-readable name that is stored on the blockchain. It can be owned by an individual or group of individuals depending on permissions configuration. An account is required to transfer or otherwise push a transaction to the blockchain.from ‘Accounts and Permissions’

Account essentially is a number of public/privates keys tided to a unique name. Keys are stored in a wallet. Accounts are stored on EOS blockchain.

Creating an account locally is easy, you just run cleos create account command because you own default eosio account, which is obviously not the case on Mainnet. In order to create account on Mainnet you need help from someone who already has it, like zeos or eos-account-creator and it costs money. Moreover, you only can create accounts which are exactly 12 symbols and consist only of a-z lower case only, 1–5 digits. This is incredibly restrictive in my opinion. To get an account with shorter names you have to bid in auction. Taking into account (pun intended) that you can resell EOS account squatting is going to be huge. With all that in mind, we are going to use Testnet for our tutorial to save money and time.

EOS Jungle Tesnet as close to the Mainnet as possible. Go to the jungle.cryptolions.io and press ‘Create Account’ link. It will ask you for the account name and two keys. Use the public keys generated before.

Confirm that account is created:

Now we need to buy some RAM for our account because in order to publish our contract. In EOS blockchain there is RAM marketplace with whales playing bulls, another great speculative opportunity for people with money.Drop some EOS tokens to your account using EOS Jungle Testnet Faucet.

After that run cleos system buyram command to buy RAM with EOS tokens.

Create Contract

First we have to upload our contract to the blockchain. Cleos command set contract does exactly that with the following positional parameters:

* account — the account to publish a contract for.* contract-dir — contract directory.* wast-file — the file containing the contract WAST or WASM.* abi-file — the ABI of the contract.

As you can seen we need to specify wast and abi files. If you have built EOS from source code you can find them at ./build/contracts/eosio.token/ folder. Just for convenience I’ve uploaded them both of them — wast/abi. Let’s call set contractcommand with our account and files. Because our wast/abi files have the same name as the directory name, we can skip these parameters.

Let’s check that code has been uploaded with get code ylvdeveloper command.

Yep, it is there.

Create Token

Finally, we can create and issue our token. We are going to utilize createand issue actions of our smart contract using cleos push action command which takes the following parameters:

* contract — the account providing the contract to execute.* action — the action to execute on the contract.* data — the arguments to the contract.

Let’s create YLV token and issue some tokens.

We just have created YLV token with maximum capacity of 1'000'000.00 tokens. Now let’s issue 1000 tokens to ylvdeveloper account.

Next, check the balance:

Great. We have our token contract and can issue tokens. What else do we need? Ability to transfer tokens from one account to another. We’ll use the same push action command from cleos with transfer method of the token smart contract. You need another account to transfer tokens to. It can be created using the same steps as we did for ylvdeveloper. We’ll send 100 tokens from ylvdeveloper to ylvio account.

Check balances:

Works as expected.

Summary

We went full path from installing cleos and learning about eosio.token smart contract to having our own token and transferring tokens out to other accounts. We did all this using EOS Jungle Testnet which is almost identical to Mainnet. The same steps will work for Mainnet, you just need to use different API endpoint and pay for accounts and RAM.

TL;DR

  • EOS token is a smart contract.
  • Cleos is command line utility used to interact with wallet and node.
  • EOS Jungle Testnet can be used for development.
  • You can create, issue and transfer your own token using eosio.token smart contract.

Related


Published by HackerNoon on 2018/07/16