EOS开发2-钱包合约案例

首先需要切换到eos/build/programs/cleos

1 钱包设置

wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos wallet create
"/Users/wsilverky/Documents/gitTools/eos/eos/build/programs/keosd/keosd" launched
Creating wallet: default
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5JWkf19kjUybLgpHD5LXNgcSc9oqh5Cs7CSggEUbVu1sDZ16Jmg"

PS:需要保存好私钥

wsilverkydeMacBook-Pro:cleos wsilverky$ vi ~/Desktop/eosPriviteKey.txt
wsilverkydeMacBook-Pro:cleos wsilverky$ cat ~/Desktop/eosPriviteKey.txt 
PW5JWkf19kjUybLgpHD5LXNgcSc9oqh5Cs7CSggEUbVu1sDZ16Jmg

2 为账号部署合约

另开个终端启动节点服务器:

wsilverkydeMacBook-Pro:config wsilverky$ cd ~/Documents/gitTools/eos/eos/build/programs/nodeos/
wsilverkydeMacBook-Pro:nodeos wsilverky$ ./nodeos 

部署合约:

wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos set contract eosio ../../contracts/eosio.bios -p eosio
Reading WAST/WASM from ../../contracts/eosio.bios/eosio.bios.wasm...
Using already assembled WASM...
Publishing contract...
executed transaction: effe553e4367e02b673b2ca6a4959a24d749b6dbdb99da87d24762c99b6756be  3720 bytes  5193 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

3 创建2个key,导入key的私钥

wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos create key
Private key: 5Jf39VYK2HLyZdXgVYYSjQ9iKgkGs8BQPrUmq567Bc4V3i7MpiK
Public key: EOS5sLrJyeX1nWc8xd8thB7DD1apCa872DjU8Dfn4sYLprmd7GLZa
wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos create key
Private key: 5JUzSB4TgSZkLWxnYPNiw4fs3bBo839hdZg5S6ScvJKCoPeLUte
Public key: EOS8DGpDx2Xyi5gCAGKR2QfNZpayrsfJYb3u913upX4a3aGrnGYX1

1.1.0版本上添加私钥方法改变:

cleos wallet import --private-key 5JXmv5N4hTgDc6NVS6J8CNT1JxDKab7M6iEyFbPewTrGkUxhuuZ -n alec_wallet
wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos wallet import 5Jf39VYK2HLyZdXgVYYSjQ9iKgkGs8BQPrUmq567Bc4V3i7MpiK
imported private key for: EOS5sLrJyeX1nWc8xd8thB7DD1apCa872DjU8Dfn4sYLprmd7GLZa
wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos wallet import 5JUzSB4TgSZkLWxnYPNiw4fs3bBo839hdZg5S6ScvJKCoPeLUte
imported private key for: EOS8DGpDx2Xyi5gCAGKR2QfNZpayrsfJYb3u913upX4a3aGrnGYX1

4 根据生成的公钥,创建账号

账号名称为:accounttest

wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos create account eosio accounttest EOS5sLrJyeX1nWc8xd8thB7DD1apCa872DjU8Dfn4sYLprmd7GLZa EOS8DGpDx2Xyi5gCAGKR2QfNZpayrsfJYb3u913upX4a3aGrnGYX1
executed transaction: 305e584b256ec9c91332c2ad0bc9b5137f2935a5daf6cba2569ca8cbb0e4a2ca  200 bytes  292 us
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"accounttest","owner":{"threshold":1,"keys":[{"key":"EOS5sLrJyeX1nWc8xd8th...
warning: transaction executed locally, but may not be confirmed by the network yet

5 查看账号信息

wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos get account accounttest -j
{
  "account_name": "accounttest",
  "privileged": false,
  "last_code_update": "1970-01-01T00:00:00.000",
  "created": "2018-06-04T17:15:40.000",
  "ram_quota": -1,
  "net_weight": -1,
  "cpu_weight": -1,
  "net_limit": {
    "used": -1,
    "available": -1,
    "max": -1
  },
  "cpu_limit": {
    "used": -1,
    "available": -1,
    "max": -1
  },
  "ram_usage": 2724,
  "permissions": [{
      "perm_name": "active",
      "parent": "owner",
      "required_auth": {
        "threshold": 1,
        "keys": [{
            "key": "EOS8DGpDx2Xyi5gCAGKR2QfNZpayrsfJYb3u913upX4a3aGrnGYX1",
            "weight": 1
          }
        ],
        "accounts": [],
        "waits": []
      }
    },{
      "perm_name": "owner",
      "parent": "",
      "required_auth": {
        "threshold": 1,
        "keys": [{
            "key": "EOS5sLrJyeX1nWc8xd8thB7DD1apCa872DjU8Dfn4sYLprmd7GLZa",
            "weight": 1
          }
        ],
        "accounts": [],
        "waits": []
      }
    }
  ],
  "total_resources": null,
  "delegated_bandwidth": null,
  "voter_info": null
}

PS:-j表示json输出

6 检测,并部署合约

在做部署前,需要先解锁钱包

 ./cleos wallet unlock -n default --password PW5JWkf19kjUybLgpHD5LXNgcSc9oqh5Cs7CSggEUbVu1sDZ16Jmg
wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos wallet unlock -n default --password PW5JWkf19kjUybLgpHD5LXNgcSc9oqh5Cs7CSggEUbVu1sDZ16Jmg
Unlocked: default
wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos get code accounttest
code hash: 0000000000000000000000000000000000000000000000000000000000000000

wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos set contract accounttest ../../contracts/eosio.token/
Reading WAST/WASM from ../../contracts/eosio.token/eosio.token.wasm...
Using already assembled WASM...
Publishing contract...
executed transaction: 7bfd56de49e25a0f533ed40578c9f57a6784d65ae6090e2e5f969c59a7c94f27  8104 bytes  1489 us
#         eosio <= eosio::setcode               {"account":"accounttest","vmtype":0,"vmversion":0,"code":"0061736d01000000017e1560037f7e7f0060057f7e...
#         eosio <= eosio::setabi                {"account":"accounttest","abi":"0e

wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos get code accounttest
code hash: 641f336aa1d08526201599c3c0ddb7a646e5ac8f9fd2493f56414d0422a0f957

7 创建货币

wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos push action accounttest create '{"issuer":"accounttest","maximum_supply":"100000.0000 CUR","can_freeze":"0","can_recall":"0","can_whitelist":"0"}' --permission accounttest@active
executed transaction: 4a6582e95a803be7650f9604d7231f9510b441397ab7125c9b812105261c251c  120 bytes  3339 us
#   accounttest <= accounttest::create          {"issuer":"accounttest","maximum_supply":"100000.0000 CUR"}
warning: transaction executed locally, but may not be confirmed by the network yet

8 发行货币

wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos push action accounttest issue '{"to":"accounttest","quantity":"1000.0000 CUR","memo":""}' --permission accounttest@active -j
{
  "transaction_id": "8bf68c54b1e58bf6b06270817a333db353af7f5826477c6d0fc4f4aaa44fca96",
  "processed": {
    "id": "8bf68c54b1e58bf6b06270817a333db353af7f5826477c6d0fc4f4aaa44fca96",
    "receipt": {
      "status": "executed",
      "cpu_usage_us": 1429,
      "net_usage_words": 15
    },
    "elapsed": 1429,
    "net_usage": 120,
    "scheduled": false,
    "action_traces": [{
        "receipt": {
          "receiver": "accounttest",
          "act_digest": "770eb3e94ccb5bd28db99e611ba26ecb43a50dd078e89ceada755dfa0ef2de9f",
          "global_sequence": 12857,
          "recv_sequence": 2,
          "auth_sequence": [[
              "accounttest",
              4
            ]
          ],
          "code_sequence": 1,
          "abi_sequence": 1
        },
        "act": {
          "account": "accounttest",
          "name": "issue",
          "authorization": [{
              "actor": "accounttest",
              "permission": "active"
            }
          ],
          "data": {
            "to": "accounttest",
            "quantity": "1000.0000 CUR",
            "memo": ""
          },
          "hex_data": "003256394f4d11328096980000000000044355520000000000"
        },
        "elapsed": 1207,
        "cpu_usage": 0,
        "console": "",
        "total_cpu_usage": 0,
        "trx_id": "8bf68c54b1e58bf6b06270817a333db353af7f5826477c6d0fc4f4aaa44fca96",
        "inline_traces": []
      }
    ],
    "except": null
  }
}

PS:注意创建的数字精度要匹配

9 查看账号信息

wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos get table accounttest accounttest accounts
{
  "rows": [{
      "balance": "1000.0000 CUR"
    }
  ],
  "more": false
}

10 转账

可使用上述方法再创建eosio账号进行转账处理

wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos push action accounttest transfer '{"from":"accounttest","to":"eosio","quantity":"50.0000 CUR","memo":"first transfer"}' -p accounttest@active -j
{
  "transaction_id": "3986197951ecfa397e52f03f91d3717f764cbb8a01dc6a8f3281ae125fc6ca7e",
  "processed": {
    "id": "3986197951ecfa397e52f03f91d3717f764cbb8a01dc6a8f3281ae125fc6ca7e",
    "receipt": {
      "status": "executed",
      "cpu_usage_us": 870,
      "net_usage_words": 18
    },
    "elapsed": 870,
    "net_usage": 144,
    "scheduled": false,
    "action_traces": [{
        "receipt": {
          "receiver": "accounttest",
          "act_digest": "3c4f8bbd71db5fb4e82663f7785c1b835912c6f97ad091eaa7a7fc769bc24bfa",
          "global_sequence": 13915,
          "recv_sequence": 3,
          "auth_sequence": [[
              "accounttest",
              5
            ]
          ],
          "code_sequence": 1,
          "abi_sequence": 1
        },
        "act": {
          "account": "accounttest",
          "name": "transfer",
          "authorization": [{
              "actor": "accounttest",
              "permission": "active"
            }
          ],
          "data": {
            "from": "accounttest",
            "to": "eosio",
            "quantity": "50.0000 CUR",
            "memo": "first transfer"
          },
          "hex_data": "003256394f4d11320000000000ea305520a107000000000004435552000000000e6669727374207472616e73666572"
        },
        "elapsed": 624,
        "cpu_usage": 0,
        "console": "",
        "total_cpu_usage": 0,
        "trx_id": "3986197951ecfa397e52f03f91d3717f764cbb8a01dc6a8f3281ae125fc6ca7e",
        "inline_traces": [{
            "receipt": {
              "receiver": "eosio",
              "act_digest": "3c4f8bbd71db5fb4e82663f7785c1b835912c6f97ad091eaa7a7fc769bc24bfa",
              "global_sequence": 13916,
              "recv_sequence": 13913,
              "auth_sequence": [[
                  "accounttest",
                  6
                ]
              ],
              "code_sequence": 1,
              "abi_sequence": 1
            },
            "act": {
              "account": "accounttest",
              "name": "transfer",
              "authorization": [{
                  "actor": "accounttest",
                  "permission": "active"
                }
              ],
              "data": {
                "from": "accounttest",
                "to": "eosio",
                "quantity": "50.0000 CUR",
                "memo": "first transfer"
              },
              "hex_data": "003256394f4d11320000000000ea305520a107000000000004435552000000000e6669727374207472616e73666572"
            },
            "elapsed": 63,
            "cpu_usage": 0,
            "console": "",
            "total_cpu_usage": 0,
            "trx_id": "3986197951ecfa397e52f03f91d3717f764cbb8a01dc6a8f3281ae125fc6ca7e",
            "inline_traces": []
          }
        ]
      }
    ],
    "except": null
  }
}

转账后查询账号信息

wsilverkydeMacBook-Pro:cleos wsilverky$ ./cleos get table accounttest accounttest accounts
{
  "rows": [{
      "balance": "950.0000 CUR"
    }
  ],
  "more": false
}
最后编辑于
?著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,128评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,316评论 3 388
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,737评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,283评论 1 287
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,384评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,458评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,467评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,251评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,688评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,980评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,155评论 1 342
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,818评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,492评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,142评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,382评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,020评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,044评论 2 352