准备
我们前面已经知道账户和钱包之间默认是不存在关系, 需要我们一步步去建立, 上一节我在钱包中也导入了默认账户eosio
我们也可以查到已经导入了eosio
cleos wallet keys
[
"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
]
创建秘钥
1: 创建秘钥对
cleos create key --to-console
Private key: 5KRwbaz1Ukk9XDquUxazobBbPTNwPVN5wdaEQJ5PW5Ce7R86Azs
Public key: EOS888whh8oyM6r59riDbPgtedp11JanruSd1DTwa4bWALMHVxH1k
cleos create key --to-console
Private key: 5JLAXGyXFNAUyUWQZLt84mwcLfY3qcVXiQqCf9UFe3FuD3TrEDE
Public key: EOS7Mt1UdXKhqcsCbcvWfdcySZ4f2R9PAZELRYEgn2gh9w2fXRb6H
2: 将私钥导入我们自己的钱包aries
cleos wallet import -n aries --private-key 5KRwbaz1Ukk9XDquUxazobBbPTNwPVN5wdaEQJ5PW5Ce7R86Azs
imported private key for: EOS888whh8oyM6r59riDbPgtedp11JanruSd1DTwa4bWALMHVxH1k
root@aries-virtual-machine:/home/aries# cleos wallet import -n aries --private-key 5JLAXGyXFNAUyUWQZLt84mwcLfY3qcVXiQqCf9UFe3FuD3TrEDE
imported private key for: EOS7Mt1UdXKhqcsCbcvWfdcySZ4f2R9PAZELRYEgn2gh9w2fXRb6H
cleos wallet keys
[
"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"EOS7Mt1UdXKhqcsCbcvWfdcySZ4f2R9PAZELRYEgn2gh9w2fXRb6H"
]
创建用户账户
1: 命令:Usage: cleos create account [OPTIONS] creator name OwnerKey [ActiveKey]
其中 creator代表用哪个账户作为创建者,当前命令是用eosio作为创建者。
name代表新账户的名字。
OwnerKey代表新账户的归属key的公钥,这个key很重要,所以在主网上面,归属key的私钥部分要严格保密。
ActiveKey代表新账户的活动key的公钥,我们当以这个账户做一些一般的签名的时候,只需要用这个key就可以了。
2: 查看公钥账户, 不存在需要创建
root@aries-virtual-machine:/home/aries# cleos get accounts EOS7Mt1UdXKhqcsCbcvWfdcySZ4f2R9PAZELRYEgn2gh9w2fXRb6H
{
"account_names": []
}
3: 开始创建, 创建一个user用户
cleos wallet keys
[
"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"EOS7Mt1UdXKhqcsCbcvWfdcySZ4f2R9PAZELRYEgn2gh9w2fXRb6H"
]
这两个key,其中EOS7Mt1UdXKhqcsCbcvWfdcySZ4f2R9PAZELRYEgn2gh9w2fXRb6H是我自己导入的,后续创建账户我们将会使用这个。
另外一个EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV是系统合约用的,也就是我们在上一篇中加载bios合约时导入的。
root@aries-virtual-machine:/home/aries# cleos create account eosio user EOS7Mt1UdXKhqcsCbcvWfdcySZ4f2R9PAZELRYEgn2gh9w2fXRb6H EOS7Mt1UdXKhqcsCbcvWfdcySZ4f2R9PAZELRYEgn2gh9w2fXRb6H
executed transaction: 9880e5c9bd756066e275731e8ac388c94949ac16e7948eccb733544124b62046 200 bytes 698 us
# eosio <= eosio::newaccount {"creator":"eosio","name":"user","owner":{"threshold":1,"keys":[{"key":"EOS7Mt1UdXKhqcsCbcvWfdcySZ4f...
warning: transaction executed locally, but may not be confirmed by the network yet ]
root@aries-virtual-machine:/home/aries# cleos create account eosio tester EOS7Mt1UdXKhqcsCbcvWfdcySZ4f2R9PAZELRYEgn2gh9w2fXRb6H EOS7Mt1UdXKhqcsCbcvWfdcySZ4f2R9PAZELRYEgn2gh9w2fXRb6H
executed transaction: b5280c74f34c69c8de19401966137e81329aac623e2305a27ef15e91c9b3785d 200 bytes 324 us
# eosio <= eosio::newaccount {"creator":"eosio","name":"tester","owner":{"threshold":1,"keys":[{"key":"EOS7Mt1UdXKhqcsCbcvWfdcySZ...
warning: transaction executed locally, but may not be confirmed by the network yet ]
root@aries-virtual-machine:/home/aries# cleos get accounts EOS7Mt1UdXKhqcsCbcvWfdcySZ4f2R9PAZELRYEgn2gh9w2fXRb6H
{
"account_names": [
"tester",
"user"
]
}
钱包、账户、基本合约系统(用于支持基本action)。下面我们可以正式展开对智能合约的学习,本章主要通过源码中已经存在的较简单的token和exchange两个合约来学习、
创建一个账户,用来执行token合约
1: 创建eosio.token 用户
root@aries-virtual-machine:/home/aries# cleos create account eosio eosio.token EOS7Mt1UdXKhqcsCbcvWfdcySZ4f2R9PAZELRYEgn2gh9w2fXRb6H EOS7Mt1UdXKhqcsCbcvWfdcySZ4f2R9PAZELRYEgn2gh9w2fXRb6H
executed transaction: 9d3cd8b396729615171a140c1e298970d81f6ce35713fa0a40f9f92f3645ad52 200 bytes 309 us
# eosio <= eosio::newaccount {"creator":"eosio","name":"eosio.token","owner":{"threshold":1,"keys":[{"key":"EOS7Mt1UdXKhqcsCbcvWf...
warning: transaction executed locally, but may not be confirmed by the network yet ]
2: 部署eosio.token智能合约
root@aries-virtual-machine:/home/aries# cleos set contract eosio.token tmp/eos/build/contracts/eosio.token -p eosio.token
Reading WASM from tmp/eos/build/contracts/eosio.token/eosio.token.wasm...
Publishing contract...
executed transaction: 5298114e32d780ec3b4ed0aa41b0f3bdc03e343db6d1d7c96f7a55b662e8fa75 8104 bytes 2082 us
# eosio <= eosio::setcode {"account":"eosio.token","vmtype":0,"vmversion":0,"code":"0061736d01000000017e1560037f7e7f0060057f7e...
# eosio <= eosio::setabi {"account":"eosio.token","abi":"0e656f73696f3a3a6162692f312e30010c6163636f756e745f6e616d65046e616d65...
warning: transaction executed locally, but may not be confirmed by the network yet ]