创建EOS钱包、公私钥、合约、代币DEMO

2019-09-03浏览量:94次

摘 要

EOS官方引荐运用Docker来装置EOS,所以咱们接下来的演示环境也切换到了Docker下操作。 1、发动本地私有链 $ sudo docker run --rm --name eosio -d -p 8888:8888 -p 9876:9876 -v /tmp/work:/work -v /tmp/eosio/data:/mnt/dev/...

EOS官方引荐运用Docker来装置EOS,所以咱们接下来的演示环境也切换到了Docker下操作。

1、发动本地私有链

$ sudo docker run --rm --name eosio -d -p 8888:8888 -p 9876:9876 -v /tmp/work:/work -v /tmp/eosio/data:/mnt/dev/data -v /tmp/eosio/config:/mnt/dev/config eosio/eos-dev /bin/bash -c "nodeos -e -p eosio --plugin eosio::wallet_api_plugin --plugin eosio::wallet_plugin --plugin eosio::producer_plugin --plugin eosio::history_plugin --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --plugin eosio::http_plugin -d /mnt/dev/data --config-dir /mnt/dev/config --http-server-address=0.0.0.0:8888 --access-control-allow-origin=* --contracts-console"

722167fd21f24f315e3e00a66faeedfbc212db4ed7aa84774417a058ca2482b3 #看到节点ID就表明发动正常了

从上面指令能够看出,咱们发动了本地节点,并加载了钱包、钱包API、区块出产等插件。

2、创立钱包

假定当时EOS装置目录为~/eos,终究一行为钱包暗码。

$ cd ~/eos

$ cleos wallet create -n simon

"/usr/local/bin/keosd" launched

Creating wallet: simon

Save password to use in the future to unlock this wallet.

Without password imported keys will not be retrievable.

"PW5Kdgdd2ZMmBXeeHxECFkjQiY71ATrDmtvM1JaqKPpnXMpSbaeaA"

3、检查钱包

刚创立的钱包默许是翻开+解锁状况的,如钱包称号周围的*号。

$ cleos wallet list
Wallets:
[
 "simon *" # 默许解锁时刻为900s,即15分钟后解锁过期 
]

4、创立公私钥

公私钥用于办理账户,账户归属谁,终究认私钥。

$ cleos create key

Private key: 5Jrnorj8fNbQdiQAELDiwJzh7BTATntbYEjLDGgw7psQXKs6TNg

Public key: EOS7je26gtYggvufrSEY38egVk9ssBQF9Go5FrKtXqQgLNDt7rQDY #ouyang账户

$ cleos create key

Private key: 5JJjmQKveVZmHNGPW9j7prWR1dxSUcg87hePBdZjQgMkLyWpyyg

Public key: EOS7jfrangqG5R7Gn5YvEk3Um7t1hBDaTPFPacjpSEcWbyGARS7P6 #yangxm账户

5、检查当时钱包导入的私钥对应的公钥

由于当时EOS是V1.0.2,会有个默许的公钥,V1.0.5后去除了,为空才是正常状况。

$ cleos wallet keys
[
 "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
]

6、用公钥创立账户

钱包有必要处于解锁状况才干创立账户。

创立ouyang,作为合约创立账户。

$ cleos create account eosio ouyang EOS7je26gtYggvufrSEY38egVk9ssBQF9Go5FrKtXqQgLNDt7rQDY

executed transaction: 690a40054f8cbbef3057a801dd9b6b82543961b21bdc4e880a32d8b2ed05e6f9 200 bytes 411 us

# eosio <= eosio::newaccount {"creator":"eosio","name":"ouyang","owner":{"threshold":1,"keys":[{"key":"EOS7je26gtYggvufrSEY38egVk...

创立yangxm,作为合约发行方账户,用于接纳代币。

$ cleos create account eosio yangxm EOS7jfrangqG5R7Gn5YvEk3Um7t1hBDaTPFPacjpSEcWbyGARS7P6
executed transaction: 3a8fc91632188e0c30211ee1fcc39e4c08325dee39a11a278d9ad9dd7f4db100 200 bytes 182 us
# eosio <= eosio::newaccount {"creator":"eosio","name":"yangxm","owner":{"threshold":1,"keys":[{"key":"EOS7jfrangqG5R7Gn5YvEk3Um7...

创立vsiryxm,作为普通用户账户,用于转账测验。

$ cleos create account eosio vsiryxm EOS7jfrangqG5R7Gn5YvEk3Um7t1hBDaTPFPacjpSEcWbyGARS7P6

executed transaction: ead5c5708857cee68c084aae971fc020d9502024088539b34aa10e9e62b46574 200 bytes 642 us

# eosio <= eosio::newaccount {"creator":"eosio","name":"vsiryxm","owner":{"threshold":1,"keys":[{"key":"EOS7jfrangqG5R7Gn5YvEk3Um...

7、将私钥导入钱包

企图绕过将私钥导入钱包这一步直接创立EOS合约,发现是报错的,有必要将私钥导入钱包之后才干操作。

$ cleos set contract ouyang build/contracts/eosio.token/ -p ouyang
Reading WAST/WASM from build/contracts/eosio.token/eosio.token.wasm...
Using already assembled WASM...
Publishing contract...
Error 3090003: provided keys, permissions, and delays do not satisfy declared authorizations
Ensure that you have the related private keys inside your wallet and your wallet is unlocked.
Error Details:
transaction declares authority '{"actor":"ouyang","permission":"active"}', but does not have signatures for it.

将两个私钥别离导入钱包:

$ cleos wallet import -n simon 5Jrnorj8fNbQdiQAELDiwJzh7BTATntbYEjLDGgw7psQXKs6TNg
imported private key for: EOS7je26gtYggvufrSEY38egVk9ssBQF9Go5FrKtXqQgLNDt7rQDY #创立过ouyang账户
$ cleos wallet import -n simon 5JJjmQKveVZmHNGPW9j7prWR1dxSUcg87hePBdZjQgMkLyWpyyg
imported private key for: EOS7jfrangqG5R7Gn5YvEk3Um7t1hBDaTPFPacjpSEcWbyGARS7P6 #创立过yangxm、vsiryxm账户

再来检查一下导入状况:

$ cleos wallet keys
[
 "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
 "EOS7je26gtYggvufrSEY38egVk9ssBQF9Go5FrKtXqQgLNDt7rQDY", #新增的
 "EOS7jfrangqG5R7Gn5YvEk3Um7t1hBDaTPFPacjpSEcWbyGARS7P6" #新增的
]

8、运用ouyang账户布置eosio.token合约

eosio.token合约为体系自带根底合约,eosio为命名空间,token为eosio下的一个合约类。

咱们能够经过检查 contracts/eosio.token/eosio.token.hpp 文件代码得知。具体解读>>

$ cleos set contract ouyang build/contracts/eosio.token/ -p ouyang
Reading WAST/WASM from build/contracts/eosio.token/eosio.token.wasm...
Using already assembled WASM...
Publishing contract...
executed transaction: bd0ae1133c9b2cd7fd56fbd66ed6ca15143de99f3669676ce120647f959f88ab 8104 bytes 2379 us
# eosio <= eosio::setcode {"account":"ouyang","vmtype":0,"vmversion":0,"code":"0061736d01000000017e1560037f7e7f0060057f7e7e7f7...
# eosio <= eosio::setabi {"account":"ouyang","abi":"0e656f73696f3a3a6162692f312e30010c6163636f756e745f6e616d65046e616d6505087...

9、创立代币

代币称号CBT,发行总量10亿。代币归属谁,终究只认账户,而账户归属谁是认密钥的。

$ cleos push action ouyang create '["eosio", "1000000000.0000 CBT", 0, 0, 0]' -p ouyang

executed transaction: 248a3f612983c42c0fbdaaccb2243861073c675a442bf7bb049bc1f210a1d9d1 120 bytes 835 us

# ouyang <= ouyang::create {"issuer":"eosio","maximum_supply":"1000000000.0000 CBT"}

10、将代币总量转给发行方

$ cleos push action ouyang issue '["yangxm", "1000000000.0000 CBT", "ouyang转给发行方yangxm"]' -p eosio
executed transaction: e0e3cbed0512309ea1215a06531809425699b32864d0e459cfcd9eac5b46a6b8 144 bytes 2008 us
# ouyang <= ouyang::issue {"to":"yangxm","quantity":"1000000000.0000 CBT","memo":"ouyang转给发行方yangxm"}
# ouyang <= ouyang::transfer {"from":"eosio","to":"yangxm","quantity":"1000000000.0000 CBT","memo":"ouyang转给发行方yangxm"}
# eosio <= ouyang::transfer {"from":"eosio","to":"yangxm","quantity":"1000000000.0000 CBT","memo":"ouyang转给发行方yangxm"}
# yangxm <= ouyang::transfer {"from":"eosio","to":"yangxm","quantity":"1000000000.0000 CBT","memo":"ouyang转给发行方yangxm"}
$ cleos get currency balance ouyang yangxm CBT
1000000000.0000 CBT

11、转账

给vsiryxm普通用户账户转账。

$ cleos push action ouyang transfer '["yangxm","vsiryxm","10000.0000 CBT","yangxm给vsiryxm转账1000个CBT"]' -p yangxm

executed transaction: c4bf101bd0e2763bd5c14c78d6e273bc71cb696e9c4832b71ee0b2b607283117 160 bytes 1912 us

# ouyang <= ouyang::transfer {"from":"yangxm","to":"vsiryxm","quantity":"10000.0000 CBT","memo":"yangxm给vsiryxm转账10000个CB...

# yangxm <= ouyang::transfer {"from":"yangxm","to":"vsiryxm","quantity":"10000.0000 CBT","memo":"yangxm给vsiryxm转账10000个CB...

# vsiryxm <= ouyang::transfer {"from":"yangxm","to":"vsiryxm","quantity":"10000.0000 CBT","memo":"yangxm给vsiryxm转账10000个CB...

12、检查余额

ouyang为创立合约账户,yangxm为发行方账户,vsiryxm为普通用户账户。

$ cleos get currency balance ouyang yangxm CBT #检查yangxm余额
999990000.0000 CBT
$ cleos get currency balance ouyang vsiryxm CBT #检查vsiryxm余额
10000.0000 CBT

小结

1、account账户是EOS网络的基本单位,能够了解成实际中的法人,终究是保存在EOS公链上的,而公私钥、钱包、钱包暗码是保存在本地的。

2、一个account账户至少能够用两个权限组owner、active来进行办理,同一个公钥具有这两个权限组,也能够是不同公钥具有这两个权限组,当然这样的权限还能够扩展成多个,只需你需求,把你的亲友团都加入到这个账户中来,一旦密钥被盗,不必忧虑,亲友团都能够协助你找回密钥,37天的审阅期,让你有满足的时刻来操作,但条件是要设计好这个权限组成员和阀值。

3、钱包的解锁时刻默许为900s,超过了要从头解锁,解锁状况为加了*星号。

二维码
牛币网
牛币网
牛币网