git clone https://github.com/libra/libra.git
切换到libra文件夹而且运行启动脚原本安装依赖:node
cd libra ./scripts/dev_setup.sh
这个安装脚本里面有如下几步git
若是遇到问题,详见解决问题github
为了链接到Libra测试网络的验证节点,按照以下方式运行客户端bash
./scripts/cli/start_cli_testnet.sh
这条命令使用cargo(Rust的包管理器)来构建并运行客户端,并把客户端链接到测试网络上的一个验证节点。网络
一旦客户端链接到测试网络上的节点,你将会看到以下输出。退出可使用 quit 命令区块链
usage: <command> <args> Use the following commands: account | a Account operations query | q Query operations transfer | transferb | t | tb <sender_account_address>|<sender_account_ref_id> <receiver_account_address>|<receiver_account_ref_id> <number_of_coins> [gas_unit_price (default=0)] [max_gas_amount (default 10000)] Suffix 'b' is for blocking. Transfer coins from account to another. help | h Prints this help quit | q! Exit this client Please, input commands: libra%
若是在构建客户端与链接测试网时出现问题,详见解决问题测试
注意:若是你想在本地运行一个验证节点,按照这里的操做进行:运行一个本地验证节点fetch
一旦你的客户端链接到了测试网,你就能够运行CLI命令来建立新帐户了。咱们将会为两个用户建立帐户(就叫Alice和Bob吧)ui
一个 libra% 的命令行前缀说明你的Libra CLI客户端正在运行中。按照下面这样输入“account”能够看到关于__account__命令的帮助信息this
libra% account usage: account <arg> Use the following args for this command: create | c Create an account. Returns reference ID to use in other operations list | la Print all accounts that were created or loaded recover | r <file path> Recover Libra wallet from the file path write | w <file name> Save Libra wallet mnemonic recovery seed to disk mint | mintb | m | mb <receiver account> <number of coins> Mint coins to the account. Suffix 'b' is for blocking
注意用CLI建立一个帐户并不会更新到区块链上,只是建立了一个本地的钥匙对。
为了建立Alice的帐户,输入下面的命令:
libra% account create
成功的话输出就像下面这样:
>> Creating/retrieving next account from wallet Created/retrieved account #0 address 3ed8e5fafae4147b2a105a0be2f81972883441cfaaadf93fc0868e7a0253c4a8
0#是Alice帐户的索引,这个16进制的字符串就是Alice的帐户地址。索引只是一种指向Alice帐户的方式。帐户索引可让用户在其余的CLI命令中便捷地指向他们所建立帐户的一个本地CLI索引。索引对于区块链来讲是没什么意义的。只有当经过挖矿或者他人转帐方式,有资金转入到Alice的帐户的时候,Alice的帐户才会在区块链上面被建立。注意你可能使用了CLI中的16进制地址。这个帐户索引只是对于帐户地址的一种便利的包装而已。
为了建立Bob的帐户,重复下面的帐户建立命令:
libra% account create
成功的话输出就像下面这样:
>> Creating/retrieving next account from wallet Created/retrieved account #1 address 8337aac709a41fe6be03cad8878a0d4209740b1608f8a81566c9a7d4b95a2ec7
#1就是Bob的帐户索引,这个16进制字符串就是Bob的帐户。
输入下面的命令能够列出你所建立的帐户:
libra% account list
成功的话输出就像下面这样:
User account index: 0, address: 3ed8e5fafae4147b2a105a0be2f81972883441cfaaadf93fc0868e7a0253c4a8, sequence number: 0 User account index: 1, address: 8337aac709a41fe6be03cad8878a0d4209740b1608f8a81566c9a7d4b95a2ec7, sequence number: 0
这个帐户的序列号(sequence number)表明的是从这个帐户发送的交易的数量。每当这个帐户发送了一笔交易被执行而且存储到了区块链中,这个数字就会增长。了解更多详见序列号
在测试网上挖矿并给帐户添加币是经过Faucet完成的。Faucet是一个和测试网一同运行的服务。这个服务存在的目的只是为了促进测试网上的挖矿速度,并且主网是没有的。它建立的Libra是没有实际价值的。假定你已经建立了Alice和Bob的帐户,各自的索引是0和1。那么你能够按照下面的步骤来添加Libra到各个帐户中
为了挖取Libra并添加到Alice的帐户中,输入下面的命令:
libra% account mint 0 110
一个成功的帐户挖取命令同时会在区块脸上建立Alice的帐户。
成功的话输出就像下面这样:
>> Minting coins Mint request submitted
注意当请求提交的时候,意味着它被成功地添加到了(测试网上的验证节点的)内存池中。这并不意味着它就会被成功执行。后面,咱们将会查询帐户余额来确认挖矿是否成功。
若是你的帐户挖矿命令没有成功提交你的请求,详见问题
为了挖取Libra并添加到Bob的帐户中,输入下面的命令:
libra% account mint 1 51
成功的话输出就像下面这样:
>> Minting coins Mint request submitted
若是你的帐户挖矿命令没有成功提交你的请求,详见问题
输入下面的命令检查Alice的帐户余额:
libra% query balance 0
成功的话输出就像下面这样:
Balance is: 110
输入下面的命令检查Bob的帐户余额:
libra% query balance 1
成功的话输出就像下面这样:
Balance is: 52
在咱们提交从Libra到Bob帐户的转帐交易以前,咱们先去查询每一个帐户的序列号(sequence number)。这将帮助咱们理解交易的执行是若是改变每一个帐户的序列号的。
libra% query sequence 0 >> Getting current sequence number Sequence number is: 0 libra% query sequence 1 >> Getting current sequence number Sequence number is: 0
在 query sequence 0
中,0是Alice帐户的索引。0这个序列号说明到目前为止,Alice和Bob的帐户都没有发送过交易。
为了提交一笔从Alice到Bob的帐户10和Libra的交易,输入下面的命令:
libra% transfer 0 1 10
成功的话输出像下面这样:
>> Transferring Transaction submitted to validator To query for transaction status, run: query txn_acc_seq 0 0 <fetch_events=true|false>
你可使用 query txn_acc_seq 0 0 true
(经过帐户和序列号的交易)这条命令来追溯刚刚提交的交易的相关信息。第一个参数是发送者帐户的本地索引,第二个参数是帐户的序列号(sequence number)。
你刚刚向测试网上的验证节点提交了一笔交易,它被包含在了验证节点的内存池中。这并不意味着你的交易已经被执行了。理论上来讲,若是系统太慢了或者负载过高,要看到结果须要一些时间,你可能须要检查好屡次帐户信息。为了查询一个索引是0的帐户,你可使用 query account_state 0
这条命令。
关于相关的转帐问题,能够看看问题
阻塞转帐命令(The Blocking Transfer command): 可使用 transferb
命令来代替 transfer
命令。 transferb
会提交交易而且只有当交易被提交到区块链上的时候才会返回到客户端提示符上。例子以下:
libra% transferb 0 1 10
交易的生命周期描述了一笔交易从提交到执行存储的生命周期。
libra% query sequence 0 >> Getting current sequence number Sequence number is: 1 libra% query sequence 1 >> Getting current sequence number Sequence number is: 0
Alice帐户(索引0)的序列号是1表明了到目前为止从Alice的帐户发出了一笔交易。Bob帐户(索引1)的序列号是0表明了到目前为止Bob的帐户尚未发送过交易。每当一个帐户发送了一笔交易。它的序列号都会增长1。
为了检查两个帐户的余额,再一次像上面同样查询余额。若是交易成功执行,你将会看到Alice帐户有100Libra同时Bob的帐户有62Libra。
libra% query balance 0 Balance is: 100 libra% query balance 1 Balance is: 62
你已经成功地在测试网上执行了一笔从Alice到Bob帐户10个Libra的交易。
rustup update
./scripts/dev_setup.sh
若是出现了构建错误,尝试移除libra文件夹的cargo的lock文件
rm Cargo.lock
若是客户端没有链接到测试网:
./scripts/cli/start_cli_testnet.sh
libra% account mint 0 110 >> Minting coins [ERROR] Error minting coins: Server unavailable, please retry and/or check **if** host passed to the client is running
libra% query account_state 0
若是(你的客户端链接到的)测试网络节点不可用,或者链接超时,你会看到这样的错误:
libra% transfer 0 1 10 >> Transferring [ERROR] Failed to perform transaction: Server unavailable, please retry and/or check if host passed to the client is running
为了解决转帐错误:
query account_state 0
quit
或者 q
来尝试退出客户端,而后从新运行下面的命令来链接到测试网络
./scripts/cli/start_cli_testnet.sh
这个例子将会使用帐户和序列号查询一笔单独的交易。
libra% query txn_acc_seq 0 0 true >> Getting committed transaction by account and sequence number Committed transaction: SignedTransaction { { raw_txn: RawTransaction { sender: 3ed8e5fafae4147b2a105a0be2f81972883441cfaaadf93fc0868e7a0253c4a8, sequence_number: 0, payload: {, transaction: peer_to_peer_transaction, args: [ {ADDRESS: 8337aac709a41fe6be03cad8878a0d4209740b1608f8a81566c9a7d4b95a2ec7}, {U64: 10000000}, ] }, max_gas_amount: 10000, gas_unit_price: 0, expiration_time: 1560466424s, }, public_key: 55af3fe3f28550a2f1e5ebf073ef193feda44344d94c463b48be202aa0b3255d, signature: Signature( R: CompressedEdwardsY: [210, 23, 214, 62, 228, 179, 64, 147, 81, 159, 180, 138, 100, 211, 111, 139, 178, 148, 81, 1, 240, 135, 148, 145, 104, 234, 227, 239, 198, 153, 13, 199], s: Scalar{ bytes: [203, 76, 105, 49, 64, 130, 162, 81, 22, 237, 159, 26, 80, 181, 111, 94, 84, 6, 152, 126, 181, 192, 62, 103, 130, 94, 246, 174, 139, 214, 3, 15], } ), } } Events: ContractEvent { access_path: AccessPath { address: 3ed8e5fafae4147b2a105a0be2f81972883441cfaaadf93fc0868e7a0253c4a8, type: Resource, hash: "217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97", suffix: "/sent_events_count/" } , index: 0, event_data: AccountEvent { account: 8337aac709a41fe6be03cad8878a0d4209740b1608f8a81566c9a7d4b95a2ec7, amount: 10000000 } } ContractEvent { access_path: AccessPath { address: 8337aac709a41fe6be03cad8878a0d4209740b1608f8a81566c9a7d4b95a2ec7, type: Resource, hash: "217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97", suffix: "/received_events_count/" } , index: 0, event_data: AccountEvent { account: 3ed8e5fafae4147b2a105a0be2f81972883441cfaaadf93fc0868e7a0253c4a8, amount: 10000000 } }
注意交易数量使用 microlibra(应该是libra的一种计量单位) 展现的。
在下面的这个例子中,咱们将会查询索引为0这个帐户的"sent"事件。你会注意到在咱们从这个帐户发送了一笔帐户以后会有一个事件。当前状态的证实(proof)也被返回了,所以能够验证没有丢失事件 - 当查询没有返回"limit"事件的时候会完成此事件。
libra% query event 0 sent 0 true 10 >> Getting events by account and event type. EventWithProof { transaction_version: 3, event_index: 0, event: ContractEvent { access_path: AccessPath { address: e7460e02058b36d28e8eef03f0834c605d3d6c57455b8ec9c3f0a3c8b89f248b, type: Resource, hash: "217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97", suffix: "/sent_events_count/" } , index: 0, event_data: AccountEvent { account: 46efbad798a739c088e0e98dd9d592c27c7eb45ba1f8ccbdfc00bd4d7f2947f3, amount: 10000000 } }, proof: EventProof { ledger_info_to_transaction_info_proof: AccumulatorProof { siblings: [HashValue(62570ae9a994bcb20c03c055667a4966fa50d0f17867dd5819465072fd2c58ba), HashValue(cce2cf325714511e7d04fa5b48babacd5af943198e6c1ac3bdd39c53c87cb84c)] }, transaction_info: TransactionInfo { signed_transaction_hash: HashValue(69bed01473e0a64140d96e46f594bc4b463e88e244b694e962b7e19fde17f30d), state_root_hash: HashValue(5809605d5eed94c73e57f615190c165b11c5e26873012285cc6b131e0817c430), event_root_hash: HashValue(645df3dee8f53a0d018449392b8e9da814d258da7346cf64cd96824f914e68f9), gas_used: 0 }, transaction_info_to_event_proof: AccumulatorProof { siblings: [HashValue(5d0e2ebf0952f0989cb5b38b2a9b52a09e8d804e893cb99bf9fa2c74ab304bb1)] } } } Last event state: Some( AccountStateWithProof { version: 3, blob: Some( AccountStateBlob { Raw: 0x010000002100000001217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc974400000020000000e7460e02058b36d28e8eef03f0834c605d3d6c57455b8ec9c3f0a3c8b89f248b00e1f50500000000000000000000000001000000000000000100000000000000 Decoded: Ok( AccountResource { balance: 100000000, sequence_number: 1, authentication_key: 0xe7460e02058b36d28e8eef03f0834c605d3d6c57455b8ec9c3f0a3c8b89f248b, sent_events_count: 1, received_events_count: 0, }, ) }, ), proof: AccountStateProof { ledger_info_to_transaction_info_proof: AccumulatorProof { siblings: [ HashValue(62570ae9a994bcb20c03c055667a4966fa50d0f17867dd5819465072fd2c58ba), HashValue(cce2cf325714511e7d04fa5b48babacd5af943198e6c1ac3bdd39c53c87cb84c), ], }, transaction_info: TransactionInfo { signed_transaction_hash: HashValue(69bed01473e0a64140d96e46f594bc4b463e88e244b694e962b7e19fde17f30d), state_root_hash: HashValue(5809605d5eed94c73e57f615190c165b11c5e26873012285cc6b131e0817c430), event_root_hash: HashValue(645df3dee8f53a0d018449392b8e9da814d258da7346cf64cd96824f914e68f9), gas_used: 0, }, transaction_info_to_account_proof: SparseMerkleProof { leaf: Some( ( HashValue(c0fbd63b0ae4abfe57c8f24f912f164ba0537741e948a65f00d3fae0f9373981), HashValue(fc45057fd64606c7ca40256b48fbe486660930bfef1a9e941cafcae380c25871), ), ), siblings: [ HashValue(4136803b3ba779bb2c1daae7360f3f839e6fef16ae742590a6698b350a5fc376), HashValue(5350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000), HashValue(a9a6bda22dd6ee78ddd3a42da152b9bd39797b7da738e9d6023f407741810378), ], }, }, }, )
在这个帐户中,咱们将会查询一个帐户的状态。
libra% query account_state 0 >> Getting latest account state Latest account state is: Account: 3ed8e5fafae4147b2a105a0be2f81972883441cfaaadf93fc0868e7a0253c4a8 State: Some( AccountStateBlob { Raw: 0x010000002100000001217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc9744000000200000003ed8e5fafae4147b2a105a0be2f81972883441cfaaadf93fc0868e7a0253c4a800e1f50500000000000000000000000001000000000000000100000000000000 Decoded: Ok( AccountResource { balance: 100000000, sequence_number: 1, authentication_key: 0x3ed8e5fafae4147b2a105a0be2f81972883441cfaaadf93fc0868e7a0253c4a8, sent_events_count: 1, received_events_count: 0, }, ) }, ) Blockchain Version: 3
为了在你的电脑上启动一个本地的验证节点并建立你本身本地的区块链网络(没有链接到Libra测试网络),须要确保你已经运行了以前所说的构建脚本,变动到Libra Core仓库的根路径,而后运行 libra_swarm
,就像下面这样:
$ cd ~/libra $ cargo run -p libra_swarm -- -s
-p libra_swarm
是cargo开始运行 libra_swarm 包,这样会启动一个包含一个节点的本地区块链。
-s
选项启动一个链接到本地区块链上的本地客户端
为了看到开启节点与链接到Libra区块脸上的额外选项,运行:
$ cargo run -p libra_swarm -- -h
cargo运行命令可能须要一些时间来运行。若是这条命令的执行了且没有错误,那么一个Libra CLI客户端的实例和一个本地的验证节点就已经运行在你的系统中了。在成功执行的基础上,你将会看到包含着CLI客户端菜单和 libra
提示符的输出。
一旦你已经完成了你的第一笔交易,你能够去看看 交易的生命周期 的文档了,目的在于: