| 知乎專欄 | 多維度架構 | | | 微信號 netkiller-ebook | | | QQ群:128659835 請註明“讀者” |
編譯 eosio.bios 合約
cd /usr/local/src/eos/build/contracts/eosio.bios [root@netkiller eosio.bios]# make [ 4%] Built target libc++ [ 4%] Built target wasm [ 4%] Built target ast [ 4%] Built target asmjs [ 4%] Built target cfg [ 10%] Built target passes [ 12%] Built target support [ 14%] Built target eosio-s2wasm [ 17%] Built target Platform [ 17%] Built target Logging [ 17%] Built target IR [ 17%] Built target WASM [ 17%] Built target WAST [ 17%] Built target eosio-wast2wasm [ 19%] Built target eosiolib [100%] Built target libc [100%] Built target eosio.bios
編譯 eosio.token 合約
cd /usr/local/src/eos/build/contracts/eosio.token [root@netkiller eosio.token]# pwd /usr/local/src/eos/build/contracts/eosio.token [root@netkiller eosio.token]# make [ 4%] Built target libc++ [ 4%] Built target wasm [ 4%] Built target ast [ 4%] Built target asmjs [ 4%] Built target cfg [ 10%] Built target passes [ 12%] Built target support [ 14%] Built target eosio-s2wasm [ 17%] Built target Platform [ 17%] Built target Logging [ 17%] Built target IR [ 17%] Built target WASM [ 17%] Built target WAST [ 17%] Built target eosio-wast2wasm [ 19%] Built target eosiolib [100%] Built target libc [100%] Built target eosio.token
從配置檔案 ~/.local/share/eosio/nodeos/config/config.ini 中查找 signature-provider
[root@netkiller ~]# grep "^signature-provider" ~/.local/share/eosio/nodeos/config/config.ini signature-provider = EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
找到 signature-provider 配置項,複製秘鑰 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
[root@netkiller ~]# cleos wallet import 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 imported private key for: EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
導入 eosio 賬號私鑰到 default 錢包
[root@netkiller ~]# cleos wallet keys [ "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" ]
創建秘鑰對
[root@netkiller ~]# cleos create key Private key: 5JFMTVk4EjWW54xk73AMRPf5JbpFV2Cm7vtgt1jr9zVaPgLmaLQ Public key: EOS7fcRYssRt5SXVnsPpRNzj86E9h5g62hBgKwr1NSzRmSpH9byZr
導入私鑰
[root@netkiller ~]# cleos wallet import 5JFMTVk4EjWW54xk73AMRPf5JbpFV2Cm7vtgt1jr9zVaPgLmaLQ imported private key for: EOS7fcRYssRt5SXVnsPpRNzj86E9h5g62hBgKwr1NSzRmSpH9byZr [root@netkiller ~]# cleos wallet keys [ "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", "EOS7fcRYssRt5SXVnsPpRNzj86E9h5g62hBgKwr1NSzRmSpH9byZr" ]
創建賬號 neo
[root@netkiller ~]# cleos wallet unlock
[root@netkiller ~]# cleos create account eosio neo EOS7fcRYssRt5SXVnsPpRNzj86E9h5g62hBgKwr1NSzRmSpH9byZr EOS7fcRYssRt5SXVnsPpRNzj86E9h5g62hBgKwr1NSzRmSpH9byZr
executed transaction: e138b1e7557d76b3560b898942db942eb23b43f8387c60083741ab4d0680e139 200 bytes 311 us
# eosio <= eosio::newaccount {"creator":"eosio","name":"neo","owner":{"threshold":1,"keys":[{"key":"EOS7fcRYssRt5SXVnsPpRNzj86E9h...
warning: transaction executed locally, but may not be confirmed by the network yet
[root@netkiller ~]# cleos wallet unlock [root@netkiller ~]# cleos set contract eosio /usr/local/src/eos/build/contracts/eosio.bios -p eosio
[root@netkiller ~]# cleos set contract eosio /usr/local/src/eos/build/contracts/eosio.bios -p eosio
Reading WAST/WASM from /usr/local/src/eos/build/contracts/eosio.bios/eosio.bios.wasm...
Using already assembled WASM...
Publishing contract...
executed transaction: c8589dc4ddb429765e86e78add1420461ce35a4edac7e08fe790e4b876a1ce29 3720 bytes 815 us
# eosio <= eosio::setcode {"account":"eosio","vmtype":0,"vmversion":0,"code":"0061736d0100000001621260037f7e7f0060057f7e7e7e7e...
# eosio <= eosio::setabi {"account":"eosio","abi":"0e656f73696f3a3a6162692f312e30050c6163636f756e745f6e616d65046e616d650f7065...
warning: transaction executed locally, but may not be confirmed by the network yet
創建賬號 netkiller 重複上面步驟,這個賬號用於創建代幣智能合約。
[root@netkiller ~]# cleos create key
Private key: 5KVTLTRgLdKj4b5FkkFpYMhYdhimPip3dtdfnZAQVQxQBBV4oFq
Public key: EOS5NyaD49BuTCScNEY8FPBCZ9t6VXThMAmFvgMg72XqcNVPXuEWH
[root@netkiller ~]# cleos wallet import 5KVTLTRgLdKj4b5FkkFpYMhYdhimPip3dtdfnZAQVQxQBBV4oFq
imported private key for: EOS5NyaD49BuTCScNEY8FPBCZ9t6VXThMAmFvgMg72XqcNVPXuEWH
[root@netkiller ~]# cleos create account eosio netkiller EOS5NyaD49BuTCScNEY8FPBCZ9t6VXThMAmFvgMg72XqcNVPXuEWH EOS5NyaD49BuTCScNEY8FPBCZ9t6VXThMAmFvgMg72XqcNVPXuEWH
executed transaction: fc87fc5cb598a24b36bf3dc10c542d7425d319d33291029de1f0c412dadea233 200 bytes 301 us
# eosio <= eosio::newaccount {"creator":"eosio","name":"netkiller","owner":{"threshold":1,"keys":[{"key":"EOS5NyaD49BuTCScNEY8FPB...
warning: transaction executed locally, but may not be confirmed by the network yet
cleos set contract netkiller /usr/local/src/eos/build/contracts/eosio.token
操作演示
[root@netkiller ~]# cleos set contract netkiller /usr/local/src/eos/build/contracts/eosio.token
Reading WAST/WASM from /usr/local/src/eos/build/contracts/eosio.token/eosio.token.wasm...
Using already assembled WASM...
Publishing contract...
executed transaction: a8bdeafdadd37b6a3b2bf1de908725028e51ae3d5f8a9e0f95e4d33b3b22b8be 8104 bytes 1411 us
# eosio <= eosio::setcode {"account":"netkiller","vmtype":0,"vmversion":0,"code":"0061736d01000000017e1560037f7e7f0060057f7e7e...
# eosio <= eosio::setabi {"account":"netkiller","abi":"0e656f73696f3a3a6162692f312e30010c6163636f756e745f6e616d65046e616d6505...
warning: transaction executed locally, but may not be confirmed by the network yet
code hash 有值表示合約部署成功
[root@netkiller ~]# cleos get code netkiller code hash: 641f336aa1d08526201599c3c0ddb7a646e5ac8f9fd2493f56414d0422a0f957
code hash 為 0 表示合約部署失敗
[root@netkiller ~]# cleos get code netkiller code hash: 0000000000000000000000000000000000000000000000000000000000000000
[root@netkiller eosio.token]# cleos wallet unlock
password: Unlocked: default
[root@netkiller eosio.token]# cleos push action netkiller create '["netkiller","1000 EOS",0,0,0]' -p netkiller
executed transaction: 7266dda0b3fde45bd03fc0ab4fdece35e66cf6e616165f113434f63394f3fa33 120 bytes 488 us
# netkiller <= netkiller::create {"issuer":"netkiller","maximum_supply":"1000 EOS"}
warning: transaction executed locally, but may not be confirmed by the network yet
[root@netkiller ~]# cleos push action netkiller create '["netkiller","10000 NRC",0,0,0]' -p netkiller
executed transaction: cbb45fcca9e140f24cd90fb6c0fbb781afcc3a1d6da4dc912a7fde79b26b7dd0 120 bytes 521 us
# netkiller <= netkiller::create {"issuer":"netkiller","maximum_supply":"10000 NRC"}
warning: transaction executed locally, but may not be confirmed by the network yet
查看合約信息
[root@netkiller ~]# cleos get currency stats netkiller EOS
{
"EOS": {
"supply": "1000 EOS",
"max_supply": "1000 EOS",
"issuer": "netkiller"
}
}
另一個方式
cleos push action netkiller create '{"issuer":"netkiller", "maximum_supply": "10.0000 EOS", "can_freeze": 1, "can_recall": 1, "can_whitelist": 1}' -p netkiller@active
cleos push action netkiller issue '["neo","1000 EOS","issue"]' -p netkiller
給 neo 賬號發放 1000 個 EOS 幣
[root@netkiller ~]# cleos push action netkiller issue '["neo","1000 EOS","issue"]' -p netkiller
executed transaction: c60760dfbdad2face6917ff28015555f1cfc293d71eb7556fc2f7ec78591229b 128 bytes 1339 us
# netkiller <= netkiller::issue {"to":"neo","quantity":"1000 EOS","memo":"issue"}
# netkiller <= netkiller::transfer {"from":"netkiller","to":"neo","quantity":"1000 EOS","memo":"issue"}
# neo <= netkiller::transfer {"from":"netkiller","to":"neo","quantity":"1000 EOS","memo":"issue"}
warning: transaction executed locally, but may not be confirmed by the network yet
cleos push action netkiller issue '{"to":"neo","quantity":"10.0000 EOS","memo":"備註信息"}' --permission netkiller@active
[root@netkiller ~]# cleos get table netkiller neo accounts
{
"rows": [{
"balance": "1000 EOS"
}
],
"more": false
}
[root@netkiller ~]# cleos get currency balance netkiller neo 1000 EOS [root@netkiller ~]# cleos get currency balance netkiller neo EOS 1000 EOS
cleos push action eosio transfer '["eosio","netkiller","100 EOS",""]' -p eosio
cleos push action contract transfer '{"from":"from_address","to":"to_address","quantity":"1.0000 EOS","memo":"測試"}' --permission neo@active
操作演示
[root@netkiller ~]# cleos get currency balance netkiller netkiller EOS
[root@netkiller ~]# cleos push action netkiller transfer '["neo","netkiller","10 EOS","memo"]' -p neo
executed transaction: 0e23837bd8a3a7876b2463cbde1d47a25d2ac2178bb42ddbccd3037416cc9e43 136 bytes 745 us
# netkiller <= netkiller::transfer {"from":"neo","to":"netkiller","quantity":"10 EOS","memo":"memo"}
# neo <= netkiller::transfer {"from":"neo","to":"netkiller","quantity":"10 EOS","memo":"memo"}
warning: transaction executed locally, but may not be confirmed by the network yet
[root@netkiller ~]# cleos get currency balance netkiller netkiller EOS
10 EOS