README ¶
BaseCoin Example
basecoin example基于qbase实现了简单的单次单币种,单个发送/接收账户的转账功能
使用步骤
- Install basecoind and basecli
在qbase项目根目录下
$ cd example/basecoin/cmd/basecoind
$ go install
$ cd ../basecli
$ go install
- 初始化
$ basecoind init --chain-id basecoin --moniker basecoin-node
{
"moniker": "basecoin-node",
"chain_id": "basecoin",
"node_id": "0048c2db694c91b2b3b272ec901cce0636d13ff3",
"gentxs_dir": "",
"app_message": {
"qcps": [
{
"name": "qstar",
"chain_id": "qstar",
"pub_key": {
"type": "tendermint/PubKeyEd25519",
"value": "ish2+qpPsoHxf7m+uwi8FOAWw6iMaDZgLKl1la4yMAs="
}
}
],
"accounts": [
{
"address": "address1y0nwp6hmxm0g0zhvuglr2jdgglns8tsdctdre6",
"coins": [
{
"coin_name": "qstar",
"amount": "100000000"
}
]
}
]
}
}
命令执行完成后,配置文件初始化完成并创建了创世账户“address1y0nwp6hmxm0g0zhvuglr2jdgglns8tsdctdre6”.
配置文件默认目录为$HOME/.basecoind/config
创世账户默认名称为
Jia
,密码为123456
. 可以通过basecli keys命令进行查看操作
- 创建本地账户"Liu"
$ basecli keys add Liu
Enter a passphrase for your key:
Repeat the passphrase:
NAME: TYPE: ADDRESS: PUBKEY:
Liu local address1q55ay4hdv33uplvvxpq0j8r7lpxunx8ytsvgkn PubKeyEd25519{8329335BCB2B26E6D6B26854B72C4722B8740AE70A4454A499468E08D16DD29C}
**Important** write this seed phrase in a safe place.
It is the only way to recover your account if you ever forget your password.
book distance cart design another view olympic orbit leopard indoor tumble dutch random feel glad brother obvious sweet unlock degree eyebrow south final rather
- 启动basecoin app
$ basecoind start
- 查询账户信息
$ basecli query account Jia
{
"type": "basecoin/AppAccount",
"value": {
"base_account": {
"account_address": "address10ly5e3qz3v3xy84ha46dylnyuuq773exa8xcxz",
"public_key": null,
"nonce": "0"
},
"coins": [
{
"coin_name": "qstar",
"amount": "100000000"
}
]
}
}
$ basecli query account Liu
ERROR: account not exists
本地账户
Liu
未在链上
- 链内交易
$ basecli tx send --from=Jia --to=Liu --coin-name=qstar --coin-amount=10
Password to sign with 'Jia':
{"check_tx":{},"deliver_tx":{},"hash":"0677BB2E156496064960ED759BFEDBE6D09A8282","height":"22"}
- 查询账户信息
$ basecli query account Jia
{
"type": "basecoin/AppAccount",
"value": {
"base_account": {
"account_address": "address10ly5e3qz3v3xy84ha46dylnyuuq773exa8xcxz",
"public_key": {
"type": "tendermint/PubKeyEd25519",
"value": "8i28U4DmFV+szuTNyzOpOurAXmN9dAuPzzsvTDNHx54="
},
"nonce": "1"
},
"coins": [
{
"coin_name": "qstar",
"amount": "99999990"
}
]
}
}
$ basecli query account Liu
{
"type": "basecoin/AppAccount",
"value": {
"base_account": {
"account_address": "address10j7njmfrfmfe5myr2scv4e8qw62027jw0kgtfu",
"public_key": null,
"nonce": "0"
},
"coins": [
{
"coin_name": "qstar",
"amount": "10"
}
]
}
}
- 查询交易
$ basecli tendermint tx 0677BB2E156496064960ED759BFEDBE6D09A8282
{
"hash": "Bne7LhVklgZJYO11m/7b5tCagoI=",
"height": "22",
"tx": {
"type": "qbase/txs/stdtx",
"value": {
"itx": {
"type": "basecoin/SendTx",
"value": {
"from": "address10ly5e3qz3v3xy84ha46dylnyuuq773exa8xcxz",
"to": "address10j7njmfrfmfe5myr2scv4e8qw62027jw0kgtfu",
"coin": {
"coin_name": "qstar",
"amount": "10"
}
}
},
"sigature": [
{
"pubkey": {
"type": "tendermint/PubKeyEd25519",
"value": "8i28U4DmFV+szuTNyzOpOurAXmN9dAuPzzsvTDNHx54="
},
"signature": "oRb4JAXgUexpBrDuu0Ez/K9cq63rvaQMA4reL/nbt2OhwUrdHT3KoIEt1bOR00G/oo+STI1QdoDs0z+NGevACA==",
"nonce": "1"
}
],
"chainid": "test-chain-vHi9Q2",
"maxgas": "0"
}
},
"result": {}
} <nil>
- QCP交易
qstar PriKey:
0xa3288910405746e29aeec7d5ed56fac138b215e651e3244e6d995f25cc8a74c40dd1ef8d2e8ac876faaa4fb281f17fb9bebb08bc14e016c3a88c6836602ca97595ae32300b
ed25519格式: V0bimu7H1e1W+sE4shXmUeMkTm2ZXyXMinTEDdHvjS6KyHb6qk+ygfF/ub67CLwU4BbDqIxoNmAsqXWVrjIwCw==
使用ed25519格式将签名私钥导入:
$ basecli keys import qcpsigner
> Enter ed25519 private key:
V0bimu7H1e1W+sE4shXmUeMkTm2ZXyXMinTEDdHvjS6KyHb6qk+ygfF/ub67CLwU4BbDqIxoNmAsqXWVrjIwCw==
> Enter a passphrase for your key:
> Repeat the passphrase:
$ basecli keys list
NAME: TYPE: ADDRESS: PUBKEY:
Jia local address1eujfrs74cptw8pzwq25a30ecd6nk8d5l97474h pDJBH9pMnPMwaEpnvX3bqCV2kPTZSSdv4S97p7gsGOw=
Liu local address1q55ay4hdv33uplvvxpq0j8r7lpxunx8ytsvgkn gykzW8srJubWsmhUtyxHIrh0CucKRFSkmUaOCNFt0pw=
qcpsigner import address103eak408d4yp944wv58epp3neyah8z5dlwyzg4 ish2+qpPsoHxf7m+uwi8FOAWw6iMaDZgLKl1la4yMAs=
发送qcp跨链交易:
$ basecli tx send --from=Jia --to=Liu --coin-name=qstar --coin-amount=10 --qcp --qcp-from=qstar --qcp-signer=qcpsigner --qcp-blockheight=10
> step 1. build and sign TxStd
Password to sign with 'Jia':
> step 2. build and sign TxQcp
Password to sign with 'qcpsigner':
{"check_tx":{},"deliver_tx":{"tags":[{"key":"cWNwLmZyb20=","value":"dGVzdC1jaGFpbi01OGczSTU="},{"key":"cWNwLnRv","value":"cXN0YXI="},{"key":"cWNwLnNlcXVlbmNl","value":"MQ=="},{"key":"cWNwLmhhc2g=","value":"DEfNVo/ucmSzIpc8rigKzxdPZ9tp8z85zOKn73zhBfg="}]},"hash":"D548E4E4173C25EE5FCBE5AB04F1FCA517F6A0A9","height":"517"}
- QCP sequence 查询
$ basecli query qcp list
|Chain |Type |MaxSequence |
|----- |---- |----------- |
|qstar |in |1 |
|qstar |out |1 |
$ basecli query qcp in qstar
1
$ basecli query qcp out qstar
1
- QCP 交易结果查询
$ basecli query qcp tx qstar --seq 1
{
"type": "qbase/txs/qcptx",
"value": {
"txstd": {
"itx": {
"type": "qbase/txs/qcpresult",
"value": {
"result": {
"Code": 0,
"Data": null,
"Log": "",
"GasWanted": "0",
"GasUsed": "0",
"FeeAmount": "0",
"FeeDenom": "",
"Tags": [
{
"key": "cWNwLmZyb20=",
"value": "dGVzdC1jaGFpbi12SGk5UTI="
},
{
"key": "cWNwLnRv",
"value": "cXN0YXI="
}
]
},
"qcporiginalsequence": "1",
"qcpextends": "",
"info": ""
}
},
"sigature": null,
"chainid": "qstar",
"maxgas": "0"
},
"from": "test-chain-vHi9Q2",
"to": "qstar",
"sequence": "1",
"sig": {
"pubkey": null,
"signature": null,
"nonce": "0"
},
"blockheight": "83",
"txindex": "0",
"isresult": true,
"extends": ""
}
} <nil>
更多命令,查阅
$ basecli --help
Click to show internal directories.
Click to hide internal directories.