EOS Contract 合约

EOS Contract 合约

在部署合约发行token,至少需要三类用户

类型 Action 账户 职责
合约账户 create eosio.token 合约托管账户,用来创建合约
发行账户 issue kevin 发行Token
交易账户 transfer coco 实现账户之间Token转移

部署合约

部署合约,需要创建一个合约托管账号eosio.token(也可以自定义)

[root@test-work2 eosio.token]# cleos wallet unlock -n kevin-wallet 
password: Unlocked: kevin-wallet

[root@test-work2 eosio.token]# cleos set contract eosio.token /root/eosio-wallet/build/contracts/eosio.contracts/contracts/eosio.token --abi eosio.token.abi -p eosio.token@active
Reading WASM from /root/eosio-wallet/build/contracts/eosio.contracts/contracts/eosio.token/eosio.token.wasm...
Publishing contract...
executed transaction: 86bf5c8cf4678828026ca890d2ded2cfcde80fa6afef9182a73b4a0791751723  6984 bytes  1673 us
#         eosio <= eosio::setcode               {"account":"eosio.token","vmtype":0,"vmversion":0,"code":"0061736d0100000001a0011b60000060017e006002...
#         eosio <= eosio::setabi                {"account":"eosio.token","abi":"0e656f73696f3a3a6162692f312e310008076163636f756e7400010762616c616e63...
warning: transaction executed locally, but may not be confirmed by the network yet         ] 

[root@test-work2 ~]# cleos get scope eosio.token
{
  "rows": [{
      "code": "eosio.token",
      "scope": ".........1a43",
      "table": "stat",
      "payer": "eosio.token",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "........cda43",
      "table": "stat",
      "payer": "eosio.token",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "coco",
      "table": "accounts",
      "payer": "kevin",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "kevin",
      "table": "accounts",
      "payer": "kevin",
      "count": 1
    }
  ],
  "more": ""
}


创建令牌 Create Token

创建代币,指定代币的发行数量,精度,代币的符号。


[root@test-work2 ~]# cleos push action eosio.token create '[ "kevin", "1000000000.0000 CL"]' -p eosio.token@active
executed transaction: adcfd825568d430d7e89d92c16b7c4602a079591cc42f97fe70e0efec1a44d32  120 bytes  397 us
#   eosio.token <= eosio.token::create          {"issuer":"kevin","maximum_supply":"1000000000.0000 CL"}
warning: transaction executed locally, but may not be confirmed by the network yet         ] 
[root@test-work2 ~]# 

#另一种方法是使用命名参数
cleos push action eosio.token create '{"issuer":"kevin", "maximum_supply":"1000000000.0000 CL"}' -p eosio.token@active

发行令牌 Issue Tokens

现在我们已经生成了代币(CL), 发行者可以将新的代币发送给其他用户

[root@test-work2 ~]# cleos push action eosio.token issue '[ "kevin", "100.0000 CL", "issue token" ]' -p kevin@active
executed transaction: 6d0067e6ed7576428f552699b23ba6fb588d1add864eab289eb330eab341fad7  128 bytes  378 us
#   eosio.token <= eosio.token::issue           {"to":"kevin","quantity":"100.0000 CL","memo":"issue token"}
warning: transaction executed locally, but may not be confirmed by the network yet         ] 
[root@test-work2 ~]# 




托管合约的abi描述信息

每个部署的托管合约,都需要指定一个账户

[root@test-work2 ~]# cleos get abi eosio.token

响应结果如下:

{
  "version": "eosio::abi/1.1",
  "types": [],
  "structs": [{
      "name": "account",
      "base": "",
      "fields": [{
          "name": "balance",
          "type": "asset"
        }
      ]
    },{
      "name": "close",
      "base": "",
      "fields": [{
          "name": "owner",
          "type": "name"
        },{
          "name": "symbol",
          "type": "symbol"
        }
      ]
    },{
      "name": "create",
      "base": "",
      "fields": [{
          "name": "issuer",
          "type": "name"
        },{
          "name": "maximum_supply",
          "type": "asset"
        }
      ]
    },{
      "name": "currency_stats",
      "base": "",
      "fields": [{
          "name": "supply",
          "type": "asset"
        },{
          "name": "max_supply",
          "type": "asset"
        },{
          "name": "issuer",
          "type": "name"
        }
      ]
    },{
      "name": "issue",
      "base": "",
      "fields": [{
          "name": "to",
          "type": "name"
        },{
          "name": "quantity",
          "type": "asset"
        },{
          "name": "memo",
          "type": "string"
        }
      ]
    },{
      "name": "open",
      "base": "",
      "fields": [{
          "name": "owner",
          "type": "name"
        },{
          "name": "symbol",
          "type": "symbol"
        },{
          "name": "ram_payer",
          "type": "name"
        }
      ]
    },{
      "name": "retire",
      "base": "",
      "fields": [{
          "name": "quantity",
          "type": "asset"
        },{
          "name": "memo",
          "type": "string"
        }
      ]
    },{
      "name": "transfer",
      "base": "",
      "fields": [{
          "name": "from",
          "type": "name"
        },{
          "name": "to",
          "type": "name"
        },{
          "name": "quantity",
          "type": "asset"
        },{
          "name": "memo",
          "type": "string"
        }
      ]
    }
  ],
  "actions": [{
      "name": "close",
      "type": "close",
      "ricardian_contract": ""
    },{
      "name": "create",
      "type": "create",
      "ricardian_contract": ""
    },{
      "name": "issue",
      "type": "issue",
      "ricardian_contract": ""
    },{
      "name": "open",
      "type": "open",
      "ricardian_contract": ""
    },{
      "name": "retire",
      "type": "retire",
      "ricardian_contract": ""
    },{
      "name": "transfer",
      "type": "transfer",
      "ricardian_contract": ""
    }
  ],
  "tables": [{
      "name": "accounts",
      "index_type": "i64",
      "key_names": [],
      "key_types": [],
      "type": "account"
    },{
      "name": "stat",
      "index_type": "i64",
      "key_names": [],
      "key_types": [],
      "type": "currency_stats"
    }
  ],
  "ricardian_clauses": [],
  "error_messages": [],
  "abi_extensions": [],
  "variants": []
}
发布了95 篇原创文章 · 获赞 50 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/jc0803kevin/article/details/105099780
今日推荐