Skip to content
On this page

下载

git clone https://github.com/libra/libra.git

任意目录下载完毕以后,只有2M左右的大小,下载很快

编译安装

libra提供了非常友好的编译安装过程,他会自动下载所有的依赖,包括rust开发工具.

txt
cd libra
./scripts/dev_setup.sh
txt
elcome to Libra!

This script will download and install the necessary dependencies needed to
build Libra Core. This includes:
	* Rust (and the necessary components, e.g. rust-fmt, clippy)
	* CMake, protobuf, go (for building protobuf)

If you'd prefer to install these dependencies yourself, please exit this script
now with Ctrl-C.

Proceed with installing necessary dependencies? (y) > y

按照提示,y即可,因为下载内容比较多,速度会比较慢.耐心等待即可,不需要科学上网. 会安装rustup,rust toolchain,CMake,protoc以及Go. Go和Rust真是一对好基友啊,现在都是区块链的主力开发工具了.

连接到Testnet

目前libra已经提供了测试开发网络,libra本质上是一个联盟链.

./scripts/cli/start_cli_testnet.sh

会编译安装client 程序,不得不说这个过程有点慢,和go比起来,编译速度不是一般的慢啊! 希望Rust这点能够学学Go,程序员也需要被善待😁.

一旦编译完成会自动进入控制台

txt
Connected to validator at: ac.testnet.libra.org:80
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%

也来看看他的启动参数吧:

client --host ac.testnet.libra.org --port 80 -s ./scripts/cli/trusted_peers.config.toml

通过这些参数也可以猜出Libra是比较中心化的.

来创建个测试账户

1. 创建Alice的账户

txt
libra% account create
>> Creating/retrieving next account from wallet
Created/retrieved account #0 address f72dde30bd92f758ab81391cf8c55ea843eeea7924d43fb0bf238600acc6f4ae
libra%

类似以太坊,是hex编码的地址,长度是32个字节,生成速度有点慢,感觉有1秒的延迟.

2. 也创建一个Bob的账户

txt
libra% account create
>> Creating/retrieving next account from wallet
Created/retrieved account #1 address 890aa80590d869d858e98c753b79113d27c2a5463ad451107dd96bcae489df8f

记得Alice的账户是#0,Bob的是#1哦.

测试交易

Libra在测试网提供了一个测试挖矿服务Faucet,这个只在测试网上存在,就是说在测试网上要多少测试币有多少测试币,这和比特币以太坊比起来,对开发友好多了.

获取测试币

txt
libra% account mint 0 100
>> Minting coins
Mint request submitted
libra%
libra% account mint 1 100
>> Minting coins
Mint request submitted

account mint 1 100表示挖100Libra到账户1,也就是Bob账户 几秒钟后,我们的Alice和Bob账户就都有了100Libra.也不清楚Libra测试网出块时间是多久. 当我尝试挖很大的金额的时候account mint 1 100000000000000000000000000,得到错误[ERROR] Error minting coins: Input value is too big: "100000000000000000000000000", max: 18446744073709.551615. 不知道这个限制只是测试网还是主网也有,需要以后主网上线才知道了.

查询账户余额

txt
libra% query balance 0
Balance is: 100
libra% query balance 1
Balance is: 100

query balance #就是查询第几个账户的余额,看起来非常清晰.

转帐试试

transfer 0 1 10 表示账户0给账户1转10.

txt
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>

再次查询账户,可以看到金额发生了变化

txt
libra% query balance 0
Balance is: 90
libra% query balance 1
Balance is: 110

当然也可以通过地址转账,形如 transfer 0 be225fe4999a7b28730d49e75140a43b03605eea07115cc37670cfaaa63b731b 20 表示通过账户0给be225fe4999a7b28730d49e75140a43b03605eea07115cc37670cfaaa63b731b这个地址转20Libra

查询账户的序列号

Libra的Sequence Number(序列号)类似于以太坊中的Nonce,基于账户模型的链都必须有此字段来防止交易重放.

libra% query sequence 0
>> Getting current sequence number
Sequence number is: 1
libra% query sequence 1
>> Getting current sequence number
Sequence number is: 0

也就是账户0发生了一笔交易.

更多关于Libra的介绍,请关注后续文章,谢谢阅读.