- 第 1 章 区块链
- 第 2 章 以太坊
- 第 3 章 以太坊私链入门
- 第 4 章 以太坊网络
- 第 5 章 geth v1.8.16 命令详解
- 第 6 章 Wallet
- 第 7 章 Token
- 第 8 章 智能合约语言 Solidity v0.5.0
- 第 9 章 Truffle v4.1.8 开发框架
- 第 10 章 web3.js - 1.0.0
- 第 11 章 web3j v3.4.0 - Jave Client
- 11.2. 启动以太坊
- 11.3. Maven pom.xml 文件
- 11.4. Java 与 Solidity 数据类型映射关系
- 11.5. 常量
- 11.6. 连接到服务器获取版本号
- 11.7. 获得以太坊状态信息
- 11.8. 单位转换
- 11.9. 账号管理
- 11.10. Credentials
- 11.11. 交易
- 11.12. 钱包
- 11.13. 智能合约
- 11.14. ERC20合约
- 11.15. Infura
- 11.16. 助记词
- 11.17. 过滤器 (Filter)
- 11.18. Subscription
- 11.19. 解锁账号
- 11.20. IBAN (International Bank Account Number)
- 11.21. Springboot with Ethereum (web3j)
- 第 12 章 web3.py - A python interface for interacting with the Ethereum blockchain and ecosystem.
- 第 14 章 Ethereum Developer APIs
- 第 15 章 infura
- 第 16 章 以太坊案例
- 第 17 章 FAQ
- 17.3. Error: authentication needed: password or unlock
- 17.4. 新增节点后不生效
- 17.5. Unhandled rejection Error: Returned error: The method personal_unlockAccount does not exist/is not available
- 17.6. Error: exceeds block gas limit
- 17.7. Migrations.sol:11:3: Warning: Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(…) { … }" instead.
- 17.8. Exception in thread "main" rx.exceptions.OnErrorNotImplementedException: Invalid response received: okhttp3.internal.http.RealResponseBody@6c25e6c4
- 17.9. 旧版本 Remix(browser-solidity) 本地安装
- 第 18 章 Hyperledger Fabric v2.0.0
- 第 19 章 Hyperledger Fabric 运维
- 第 20 章 Chaincode 链码(智能合约)
- 第 21 章 Hyperledger Fabric Client SDK for Node.js
- 第 22 章 fabric-sdk-java
- 第 24 章 已知 Hyperledger 落地案例
- 第 25 章 Fabric Command
- 第 26 章 Fabric FAQ
- 第 27 章 IPFS(InterPlanetary File System,星际文件系统)
- 第 28 章 IPFS 命令
- 第 29 章 IPFS WebUI
- 第 30 章 IPFS 集群配置
- 第 31 章 IPFS API
- 第 32 章 IPFS Faq
- 第 33 章 EOS
- 第 34 章 EOS 安装
- 第 35 章 CLEOS
- 第 36 章 智能合约开发
- 第 37 章 EOS Dapp 开发
- 第 38 章 FAQ
- 第 39 章 BaaS (Blockchain as a Service) 平台
- 第 40 章 BitCoin
- 第 41 章 其他区块链相关
- 附录 1. 附录
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
35.5. 智能合约 - EOS 代币
35.5. 智能合约 - EOS 代币
35.5.1. 编译智能合约
编译 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
35.5.2. 设置初始化账号 eosio
从配置文件 ~/.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" ]
35.5.3. 创建账号
创建秘钥对
[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
35.5.4. 部署合约 eosio.bios
[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
35.5.5. 创建账号 netkiller
创建账号 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
35.5.6. EOS 代币合约
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
35.5.7. 创建代币
[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
35.5.8. 发放代币
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
35.5.9. 查看代币余额
[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
35.5.10. 转账
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论