Deploy, Issue and Transfer Tokens

Step 1: Obtain Contract Sourcearrow-up-right

Navigate to your contracts directory.

cd CONTRACTS_DIR

Pull the latest release

This repository contains several contracts, but it's the eosio.token contract that is important for this section.

cd reference-contracts/contracts/eosio.token

Step 2: Create Account for Contractarrow-up-right

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.

circle-info

INFO

You need to unlock your wallet prior to the next step.

cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV

Step 3: Compile the Contractarrow-up-right

cdt-cpp -I include -o eosio.token.wasm src/eosio.token.cpp --abigen

Step 4: Deploy the Token Contractarrow-up-right

cleos set contract eosio.token CONTRACTS_DIR/reference-contracts/contracts/eosio.token --abi eosio.token.abi -p eosio.token@active

Step 5: Create the Tokenarrow-up-right

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:

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 eosio.token@active was passed to authorize this action.

An alternate approach uses named arguments:

Execute the command above:

Step 6: Issue Tokensarrow-up-right

The issuer alice can now issue new tokens. As mentioned earlier only the issuer can do so, therefore, -p alice@active must be provided to authorize the issue action.

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.

Step 7: Transfer Tokensarrow-up-right

Now that account alice has been issued tokens, transfer some of them to account bob.

Now check if bob received the tokens using cleos get currency balancearrow-up-right

Check alice's balance. Notice that tokens were deducted from the account.

Excellent! Everything adds up.

What's Next?arrow-up-right

Last updated