Photo by Aleksey Shmatov
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.
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.
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.
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.
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.
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 contract
command 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.
Finally, we can create and issue our token. We are going to utilize create
and 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.
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.