CoinEx链测试网CLI体验

CoinEx Chain Testnet CLI体验

CoinEx链是CoinEx发布的DEX公链,目前最新的测试网是testnet2006,读者可以跟着本文使用CoinEx链提供的命令行工具来体验测试网功能。

获取命令行工具

这里可以直接下载CoinEx链CLI工具cetcli,目前有预编译好的Linux和masOS版二进制可执行文件。以macOS操作系统为例,下载完后,执行cetcli命令,可以看到类似下面这样的输出:

$ cd testcet/
$ wget https://raw.githubusercontent.com/coinexchain/testnets/master/coinexdex-test2006/mac_osx/cetcli
$ chmod a+x ./cetcli
$ ./cetcli
Command line interface for interacting with cetd

Usage:
  cetcli [command]

Available Commands:
  status      Query remote node for status
  config      Create or query an application CLI configuration file
  query       Querying subcommands
  tx          Transactions subcommands
  rest-server Start LCD (light-client daemon), a local REST server
  keys        Add or view local private keys
  version     Print the app version
  help        Help about any command
...

生成本地密钥

cetcli有个子命令keys,可以用来添加、更新、或者删除本地密钥🔑。keys子命令本身又包含几个子命令,比如add子命令用来添加密钥。执行下面的命令可以在本地添加一个密钥,并将其和bob关联起来:

$ ./cetcli keys add bob
Enter a passphrase to encrypt your key to disk:********
Repeat the passphrase:********

- name: bob
  type: local
  address: cettest1te76rj9p8qrstzyp5mknvekpcsfdr9hjj9mw7j
  pubkey: cettestpub1addwnpepq2r3vs3yam4mu0z6r79f86f9aqrhxd88e9mzugvcs354hljk4n50uwekevp
  mnemonic: ""
  threshold: 0
  pubkeys: []


**Important** write this mnemonic phrase in a safe place.
It is the only way to recover your account if you ever forget your password.

flight bring crush magnet tobacco ball visual onion level youth hurry rather scene select art clarify mention lens stomach forget fade inject seat foam

从输出中还可以看到公钥和测试网账户地址(以cettest开头)等信息。当然,事后也可以执行cetcli keys show命令来查看密钥信息:

$ ./cetcli keys show bob
- name: bob
  type: local
  address: cettest1te76rj9p8qrstzyp5mknvekpcsfdr9hjj9mw7j
  pubkey: cettestpub1addwnpepq2r3vs3yam4mu0z6r79f86f9aqrhxd88e9mzugvcs354hljk4n50uwekevp
  mnemonic: ""
  threshold: 0
  pubkeys: []

:bulb:小提示:执行cetcli keys -h命令可以查看keys子命令的帮助信息;执行.cetcli keys add -h命令可以查看add子命令的帮助信息。其他子命令也可以通过同样的方式来查看帮助信息。

:bulb:小提示:cetcli在本地文件中存储密钥等信息,在macOS上这些文件默认存放在$HOME/.cetcli/目录下,可以通过cetcli命令提供的--home选项指定其他目录。

:bulb:小提示:bob只是密钥的别名而已

获取测试网CET

既然密钥已经有了,那么下一步就是获取CET(CoinEx Token)了。好在测试网可以轻易获得CET😊,打开测试网水龙头,把前面生成好的地址粘贴到地址栏里,然后点击“Send me tokens”即可:

体验测试网浏览器

打开测试网浏览器,查看交易,可以看到bob的100万CET已经到账(系统收了0.02个CET作为手续费😄):

通过查看交易详情可以进一步确认这一点:

还可以通过查看账户信息来确认这一点:

转账

为了体验转账,我们在本地再生成一个密钥,并把它和jay关联:

$ ./cetcli keys add jay
Enter a passphrase to encrypt your key to disk:
Repeat the passphrase:

- name: jay
  type: local
  address: cettest1tuj25se6w2x0pd9u8f68tktjd333kuqppva7dc
  pubkey: cettestpub1addwnpepqfgjryrthyuq0p7j6wfa7jw8n82ue0jx4dnahk4kwa48kame2vugqervjva
  mnemonic: ""
  threshold: 0
  pubkeys: []

然后我们可以执行cetcli tx send命令给jay转一笔CET(比如100个):

$ ./cetcli tx send cettest1tuj25se6w2x0pd9u8f68tktjd333kuqppva7dc 10000000000cet \
  --from bob \
  --node=47.75.208.217:26657 \
  --chain-id=coinexdex-test2006 \
  --gas-prices=20.0cet

这个命令稍微有点复杂,值得解释一下:

  • cettest1tuj25se6w2x0pd9u8f68tktjd333kuqppva7dc 这是接收者的地址,也就是刚刚生成的jay的地址
  • 10000000000cet 这是转账金额注意:这里CET被细分成了100000000份,所以我转的其实是100个CET
  • --from选项指定转出者,这里我指定了最开始创建的bob(直接把bob换成他的地址cettest1te76rj9p8qrstzyp5mknvekpcsfdr9hjj9mw7j也是可以的)
  • --node选项指定测试网节点的RPC地址(可以从这里查到)
  • --chain-id指定测试网的链ID
  • --gas-prices选项指定想要给出的Gas费

:bulb:小提示:还可以通过--gas选项指定Gas数(默认是200000)

关于send命令更详细的说明可以通过执行cetcli tx send -h命令查看。下面是给jay转账的send命令的完整输出(其间cetcli命令会在命令行中请求输入bob的密码,以便获取私钥给交易签名):

{"chain_id":"coinexdex-test2006","account_number":"46","sequence":"0","fee":{"amount":[{"denom":"cet","amount":"4000000"}],"gas":"200000"},"msgs":[{"type":"bankx/MsgSend","value":{"from_address":"cettest1te76rj9p8qrstzyp5mknvekpcsfdr9hjj9mw7j","to_address":"cettest1tuj25se6w2x0pd9u8f68tktjd333kuqppva7dc","amount":[{"denom":"cet","amount":"10000000000"}],"unlock_time":"0"}}],"memo":""}

confirm transaction before signing and broadcasting [y/N]: y
Password to sign with 'bob':
height: 0
txhash: 7D89A2363D89E0FCF3FDF0973F1BC2486CF758BBCF64506D55956120DED88C47
code: 0
data: ""
rawlog: '[{"msg_index":0,"success":true,"log":"","events":[{"type":"message","attributes":[{"key":"action","value":"send"}]}]}]'
logs:
- msgindex: 0
  success: true
  log: ""
  events:
  - type: message
    attributes:
    - key: action
      value: send
info: ""
gaswanted: 0
gasused: 0
codespace: ""
tx: null
timestamp: ""
events: []

从命令输出可以看到,转账成功了,并且打印出了交易哈希:7D89A2363D89E0FCF3FDF0973F1BC2486CF758BBCF64506D55956120DED88C47。用区块浏览器查看该交易可知,转账的确成功了。jay收到了bob转给他的100个CET:

发行Token

CoinEx链是个去中心化交易所(DEX),任何人都可以发行Token(只要有CET😊)。我们让bob来发一个token,名字就叫bbb好了😅:

$ ./cetcli tx asset issue-token \
  --symbol=bbb \
  --name="bob's token" \
  --description="bob's token" \
  --url="www.bbb.org" \
  --identity="552A83BA62F9B1F8" \
  --total-supply=100000000000000 \
  --mintable=false \
  --burnable=true \
  --addr-forbiddable=true \
  --token-forbiddable=true \
  --from=bob \
  --node=47.75.208.217:26657 \
  --chain-id=coinexdex-test2006 \
  --gas-prices=20.0cet

有了之前的体验,这个命令也就不那么难理解了:

  • Token的符号用--symbol指定
  • 名称等描述性信息用--name--description--url--identity选项指定
  • 总发行量用--total-supply选项指定
  • 后续是否可以增发通过--mintable选项指定
  • 后续是否可以燃烧通过--burnable选项指定
  • 是否可以按地址或全局禁止转账通过--addr-forbiddable--token-forbiddable这两个选项指定
  • 其他选项前面已经解释过了

更多帮助信息可以执行cetcli tx asset issue-token -h命令查看。下面是bbb发行命令的完整输出:

{"chain_id":"coinexdex-test2006","account_number":"46","sequence":"1","fee":{"amount":[{"denom":"cet","amount":"4000000"}],"gas":"200000"},"msgs":[{"type":"asset/MsgIssueToken","value":{"name":"bob's token","symbol":"bbb","total_supply":"100000000000000","owner":"cettest1te76rj9p8qrstzyp5mknvekpcsfdr9hjj9mw7j","mintable":false,"burnable":true,"addr_forbiddable":true,"token_forbiddable":true,"url":"www.bbb.org","description":"bob's token","identity":"552A83BA62F9B1F8"}}],"memo":""}

confirm transaction before signing and broadcasting [y/N]: y
Password to sign with 'bob':
height: 0
txhash: C6611A7364999B9BB048D5F1ECC354E25C2B30B5F0AB267AEAD86176A8191DAA
code: 0
data: ""
rawlog: '[{"msg_index":0,"success":true,"log":"","events":[{"type":"message","attributes":[{"key":"action","value":"issue_token"}]}]}]'
logs:
- msgindex: 0
  success: true
  log: ""
  events:
  - type: message
    attributes:
    - key: action
      value: issue_token
info: ""
gaswanted: 0
gasused: 0
codespace: ""
tx: null
timestamp: ""
events: []

用浏览器查看交易可知,发行成功了👏:

用区块浏览器看可以查看token的详细信息

关于CoinEx链的体验就先到这里。实际上还有许多功能我们没有体验,尤其是DEX核心功能,比如创建交易对、创建订单等。由于功能太多了,没办法在一篇文章里全部介绍。感兴趣的读者可以通过-h选项查看CLI各个命令的帮助信息,或者参考CoinEx链提供的参考手册

2 Likes