1.前言
之前我们都是运行在EOS本地节点的,如果想加入主网或者测试网络,有两种方式。
一种是同步主网/测试网的所有区块数据,自己成为一个节点。这种方式在测试网络上还可以注册成为生产区块的节点,并拉票成为超级节点,获得真正出块的权力。
另外一种是通过连接第三方节点的方式,自己不需要同步区块数据。这篇文章讲的就是第二种连接方式。
2.准备工作
创建一个钱包,管理测试网络的私钥
创建一个名为testnet.wallet
的钱包
yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet create -n testnet --to-console
Creating wallet: testnet
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5Kxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
创建两个私钥
yuyangdeMacBook-Pro:cleos yuyang$ cleos create key --to-console
Private key: 5KPZxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Public key: EOS6cnhSLTn4eSUEqS4nC8frYTsVsjeH2M3hos1TUeCgme2Yim5Q5
yuyangdeMacBook-Pro:cleos yuyang$ cleos create key --to-console
Private key: 5Kfexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Public key: EOS6Z7mUQeFC2cQTT3xMyZh2wsLQoHih1bTMgRhr3dbichprTi7Rc
导入私钥
yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet import --private-key 5KPZxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -n testnet
imported private key for: EOS6cnhSLTn4eSUEqS4nC8frYTsVsjeH2M3hos1TUeCgme2Yim5Q5
yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet import --private-key 5Kfexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -n testnet
imported private key for: EOS6Z7mUQeFC2cQTT3xMyZh2wsLQoHih1bTMgRhr3dbichprTi7Rc
查看私钥
yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet private_keys --password PW5Kxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -n testnet
[[
"EOS6Z7mUQeFC2cQTT3xMyZh2wsLQoHih1bTMgRhr3dbichprTi7Rc",
"5Kfexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
],[
"EOS6cnhSLTn4eSUEqS4nC8frYTsVsjeH2M3hos1TUeCgme2Yim5Q5",
"5KPZxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
]
]
3.测试网络
3.1 通过Jungle Testnet创建账户
打开Jungle Testnet
http://jungle.cryptolions.io
点击Create account
起一个账户名称,然后输入刚才生成的两个私钥对应的公钥
3.2 免费获取测试eos
点击Faucet
输入刚才创建的账户名称。每6小时获取一次
3.3 获取第三方节点IP
点击API endpoints
随意选择一个节点IP
http://jungle.cryptolions.io:18888
3.4 通过第三方节点与测试网络交互
使用cleos -u http://jungle.cryptolions.io:18888
指定我们要交互的节点IP
查询chain_id
:
yuyangdeMacBook-Pro:cleos yuyang$ cleos -u http://jungle.cryptolions.io:18888 get info
{
"server_version": "e87d245d",
"chain_id": "038f4b0fc8ff18a4f0842a8f0564611f6e96e8535901dd45e43ac8691a1c4dca",
"head_block_num": 13203870,
"last_irreversible_block_num": 13203541,
"last_irreversible_block_id": "00c97855858529dc1252cf54ac19720308756ad9302e5d38ecfedccc485d66ae",
"head_block_id": "00c9799e9749073571d3499eb66774d6d260144f8bb8099a43969353f95fab8c",
"head_block_time": "2018-09-05T03:08:53.500",
"head_block_producer": "lioninjungle",
"virtual_block_cpu_limit": 200000000,
"virtual_block_net_limit": 1048576000,
"block_cpu_limit": 199900,
"block_net_limit": 1048576,
"server_version_string": "v1.2.3-dirty"
}
038f4b0fc8ff18a4f0842a8f0564611f6e96e8535901dd45e43ac8691a1c4dca
表示我们连接的是测试网络
查询下刚才在测试网络上创建的账户信息:
yuyangdeMacBook-Pro:cleos yuyang$ cleos -u http://jungle.cryptolions.io:18888 get account testnetyy111
permissions:
owner 1: 1 EOS6cnhSLTn4eSUEqS4nC8frYTsVsjeH2M3hos1TUeCgme2Yim5Q5
active 1: 1 EOS6Z7mUQeFC2cQTT3xMyZh2wsLQoHih1bTMgRhr3dbichprTi7Rc
memory:
quota: 170.8 KiB used: 3.365 KiB
net bandwidth:
staked: 100.0000 EOS (total stake delegated from account to self)
delegated: 0.0000 EOS (total staked delegated to account from others)
used: 0 bytes
available: 18.32 MiB
limit: 18.32 MiB
cpu bandwidth:
staked: 100.0000 EOS (total stake delegated from account to self)
delegated: 0.0000 EOS (total staked delegated to account from others)
used: 0 us
available: 3.661 sec
limit: 3.661 sec
EOS balances:
liquid: 10000.0000 EOS
staked: 200.0000 EOS
unstaking: 0.0000 EOS
total: 10200.0000 EOS
producers: <not voted>
可以看到创建账号的时候,系统为此账号购买了170kb
的RAM
,NET
和CPU
各抵押了100 EOS
,加上我们申请的10000 EOS
,现在此账号共有10200 EOS
4.主网
与测试网络相同,指定我们要交互的主网节点的IP
主网节点IP有很多,这里同样随意选择一个https://api.eosnewyork.io
查询chain_id
:
yuyangdeMacBook-Pro:cleos yuyang$ cleos -u https://api.eosnewyork.io get info
{
"server_version": "e87d245d",
"chain_id": "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906",
"head_block_num": 14790451,
"last_irreversible_block_num": 14790132,
"last_irreversible_block_id": "00e1adf44e75aac5ac5b32064caa205934bb193242ccb83e7edeb32f61392dc2",
"head_block_id": "00e1af3323210832fde9f60160a627bdea01b96274deb16bfb1c8321a664507c",
"head_block_time": "2018-09-05T03:41:06.000",
"head_block_producer": "eos42freedom",
"virtual_block_cpu_limit": 32580927,
"virtual_block_net_limit": 1048576000,
"block_cpu_limit": 199900,
"block_net_limit": 1048576,
"server_version_string": "v1.2.3-dirty"
}
aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906
表示我们连接的是主网络
查询下我之前在主网络上创建的账户信息:
yuyangdeMacBook-Pro:cleos yuyang$ cleos -u https://api.eosnewyork.io get account yuyangray222
permissions:
owner 1: 1 EOSxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
active 1: 1 EOSxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
memory:
quota: 130.9 KiB used: 3.959 KiB
net bandwidth:
staked: 0.5000 EOS (total stake delegated from account to self)
delegated: 0.0500 EOS (total staked delegated to account from others)
used: 232 bytes
available: 366.9 KiB
limit: 367.1 KiB
cpu bandwidth:
staked: 0.8000 EOS (total stake delegated from account to self)
delegated: 0.0500 EOS (total staked delegated to account from others)
used: 2.971 ms
available: 14.99 ms
limit: 17.97 ms
EOS balances:
liquid: 0.0785 EOS
staked: 1.3000 EOS
unstaking: 0.0000 EOS
total: 1.3785 EOS
producers: <not voted>