EOS之eosio.token合约的部署和发放token

EOS之eosio.token合约的部署和发放token_第1张图片

eosio.token智能合约

在eos目录中自带的合约中,有一个eosio.token智能合约,这个智能合约的功能是为账户发放token,token可以用来转账操作。

操作步骤

在eos私有节点操作中,我们通常是一个合约对应一个合约账户,并且一个账户中只能部署一个智能合约。如果在同一个账户部署多个合约,那么最后部署的合约会覆盖掉之前的合约。

  • 创建用来部署合约的账户
cleos create account eosio eosio.token EOS8kTP7dWruLSZidZfRkcaQiwKPS1eApwnojeBo6QnaVKt2rMGMM EOS8kTP7dWruLSZidZfRkcaQiwKPS1eApwnojeBo6QnaVKt2rMGMM
executed transaction: 46c68f270dfceb36ce2270a6bad89ca2228b9750a19a3a3bc92578a46637fbb1 352 bytes 102400 cycles
# eosio <= eosio::newaccount {"creator":"eosio","name":"eosio.token","owner":{"threshold":1,"keys":[{"key":"EOS8kTP7dWruLSZidZfRk...
  • 把eosio.token合约部署到eosio.token账户上
cleos set contract eosio.token ../eosio.token
Reading WAST/WASM from build/contracts/eosio.token/eosio.token.wast...
Assembling WASM...
Publishing contract...
executed transaction: 5a0305bcab99b9d9f8590f51ce4d55bb0a0e60c2d79f4d61cd1ab210571171e2 8288 bytes 2200576 cycles
# eosio <= eosio::setcode {"account":"eosio.token","vmtype":0,"vmversion":0,"code":"0061736d010000000183011560067f7e7f7f7f7f00...
# eosio <= eosio::setabi {"account":"eosio.token","abi":{"types":[],"structs":[{"name":"transfer","base":"","fields":[{"name"...
  • 创建代币
cleos push action eosio.token create '[ "eosio", "1000000000.0000 EOS", 0, 0, 0]' -p eosio.token
executed transaction: b6ffc0fbb62ff4c23b7d24b8b55a34bf0c74e7c710b18d16af326b939ae9ecfd 248 bytes 104448 cycles
# eosio.token <= eosio.token::create {"issuer":"eosio","maximum_supply":"1000000000.0000 EOS","can_freeze":0,"can_recall":0,"can_whitelis...
  • 为账户发放token
cleos push action eosio.token issue '[ "lilei", "1000.0000 EOS", "" ]' -p eosio
executed transaction: 8e33d754aa7dd8987522c3c76ab9a1bffada096363f71169e6da71d444552631 248 bytes 124928 cycles
# eosio.token <= eosio.token::issue {"to":"lilei","quantity":"1000.0000 EOS","memo":""}
>> issue
# eosio.token <= eosio.token::transfer {"from":"eosio","to":"lilei","quantity":"1000.0000 EOS","memo":""}
>> transfer
# eosio <= eosio.token::transfer {"from":"eosio","to":"lilei","quantity":"1000.0000 EOS","memo":""}
# lilei <= eosio.token::transfer {"from":"eosio","to":"lilei","quantity":"1000.0000 EOS","memo":""}
  • 查询余额
cleos get table eosio.token lilei accounts
{
  "rows": [{
      "balance": "1000.0000 EOS",
      "frozen": 0,
      "whitelist": 1
    }
  ],
  "more": false
}

可以看到,lilei的token已经到账了。如果他真有
1000个EOS,那他就可以出去买买买了。

EOS之eosio.token合约的部署和发放token_第2张图片

你可能感兴趣的:(区块链)