telos docs
Search…
2.2: Deploy, Issue and Transfer Tokens

Step 1: Obtain Contract Source

Navigate to your contracts directory.
Pull the source
1
git clone https://github.com/EOSIO/eosio.contracts --branch v1.7.0 --single-branch
Copied!
This repository contains several contracts, but it's the eosio.token contract that is important for this section. Navigate to the eosio.contracts/contracts/eosio.token directory.
1
cd eosio.contracts/contracts/eosio.token
Copied!

Step 2: Create Account for Contract

Before we can deploy the token contract we must create an account to deploy it to, we'll use the eosio development key for this account.
[[info]] | You need to unlock your wallet prior to the next step
1
cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
Copied!

Step 3: Compile the Contract

1
eosio-cpp -I include -o eosio.token.wasm src/eosio.token.cpp --abigen
Copied!

Step 4: Deploy the Token Contract

1
cleos set contract eosio.token CONTRACTS_DIR/eosio.contracts/contracts/eosio.token --abi eosio.token.abi -p [email protected]
Copied!
1
Reading WASM from ...eosio.contracts/contracts/eosio.token/eosio.token.wasm...
2
Publishing contract...
3
executed transaction: a68299112725b9f2233d56e58b5392f3b37d2a4564bdf99172152c21c7dc323f 6984 bytes 6978 us
4
# eosio <= eosio::setcode {"account":"eosio.token","vmtype":0,"vmversion":0,"code":"0061736d0100000001a0011b60000060017e006002...
5
# eosio <= eosio::setabi {"account":"eosio.token","abi":"0e656f73696f3a3a6162692f312e310008076163636f756e7400010762616c616e63...
6
warning: transaction executed locally, but may not be confirmed by the network yet ]
Copied!

Step 5: Create the Token

To create a new token, call create action with the correct parameters. This action accepts 1 argument, it consists of:
  • An issuer that is an eosio account. In this case, it's alice. This issuer will be the one with the authority to call issue and/or perform other actions such as closing accounts or retiring tokens.
  • An asset type composed of two pieces of data, a floating-point number sets the maximum supply and a symbol in capitalized alpha characters which represents the asset. For example, "1.0000 SYS".
Below is a concise way to call this method, using positional arguments:
1
cleos push action eosio.token create '[ "alice", "1000000000.0000 SYS"]' -p [email protected]
Copied!
The command above created a new token SYS with a precision of 4 decimals and a maximum supply of 1000000000.0000 SYS. It also designates alice as the issuer. To create this token, the contract requires the permission of the eosio.token account. For this reason, -p [email protected] was passed to authorize this action.
An alternate approach uses named arguments:
1
cleos push action eosio.token create '{"issuer":"alice", "maximum_supply":"1000000000.0000 SYS"}' -p [email protected]
Copied!
Execute the command above:
1
executed transaction: 10cfe1f7e522ed743dec39d83285963333f19d15c5d7f0c120b7db652689a997 120 bytes 1864 us
2
# eosio.token <= eosio.token::create {"issuer":"alice","maximum_supply":"1000000000.0000 SYS"}
3
warning: transaction executed locally, but may not be confirmed by the network yet ]
Copied!

Step 6: Issue Tokens

The issuer alice can now issue new tokens. As mentioned earlier only the issuer can do so, therefore, -p [email protected] must be provided to authorize the issue action.
1
cleos push action eosio.token issue '[ "alice", "100.0000 SYS", "memo" ]' -p [email protected]
Copied!
1
executed transaction: d1466bb28eb63a9328d92ddddc660461a16c405dffc500ce4a75a10aa173347a 128 bytes 205 us
2
# eosio.token <= eosio.token::issue {"to":"alice","quantity":"100.0000 SYS","memo":"memo"}
3
warning: transaction executed locally, but may not be confirmed by the network yet ]
Copied!
This time the output contains several actions: one issue action and three transfer actions. While the only action signed was issue, the issue action performed an inline transfer and the inline transfer notified the sender and receiver accounts. The output indicates all the action handlers that were called, the order they were called in, and whether any output was generated by the action.
Technically, the eosio.token contract could have skipped the inline transfer and opted to just modify the balances directly. However, in this case the eosio.token contract is following a token convention that requires that all account balances be derivable by the sum of the transfer actions that reference them. It also requires that the sender and receiver of funds be notified so they can automate handling deposits and withdrawals.
To inspect the transaction, try using the -d -j options, which indicate "don't broadcast" and "return the transaction as json", which you may find useful during development.
1
cleos push action eosio.token issue '["alice", "100.0000 SYS", "memo"]' -p [email protected] -d -j
Copied!

Step 7: Transfer Tokens

Now that account alice has been issued tokens, transfer some of them to account bob.
1
cleos push action eosio.token transfer '[ "alice", "bob", "25.0000 SYS", "m" ]' -p [email protected]
Copied!
1
executed transaction: 800835f28659d405748f4ac0ec9e327335eae579a0d8e8ef6330e78c9ee1b67c 128 bytes 1073 us
2
# eosio.token <= eosio.token::transfer {"from":"alice","to":"bob","quantity":"25.0000 SYS","memo":"m"}
3
# alice <= eosio.token::transfer {"from":"alice","to":"bob","quantity":"25.0000 SYS","memo":"m"}
4
# bob <= eosio.token::transfer {"from":"alice","to":"bob","quantity":"25.0000 SYS","memo":"m"}
5
warning: transaction executed locally, but may not be confirmed by the network yet ]
Copied!
Now check if bob received the tokens using cleos get currency balance
1
cleos get currency balance eosio.token bob SYS
Copied!
1
25.0000 SYS
Copied!
Check alice's balance. Notice that tokens were deducted from the account.
1
cleos get currency balance eosio.token alice SYS
Copied!
1
75.0000 SYS
Copied!
Excellent! Everything adds up.

What's Next?

  • Understanding ABI Files: Introduction to Application Binary Files (ABI) and how the ABI file correlates to the eosio.token contract.
Last modified 1yr ago