Facebook 虚拟货币 Libra 尝鲜
总结自《发起第一笔 Libra 转账极简教程》
搭建 Libra 的环境步骤如下:
- 克隆并编译 Libra Core
$git clone https://github.com/libra/libra.git
$cd libra
$./scripts/dev_setup.sh
- 编译客户端并连接到测试网络
$./scripts/cli/start_cli_testnet.sh
这条命令会编译客户端,并把客户端连接到 Libra 测试网络中的验证节点上。
连接成功后,会看到这些输出信息:
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%
- 创建测试账户
libra% account create
>> Creating/retrieving next account from wallet
Created/retrieved account #0 address c67ba7dce978ede151ed21f926a04733805dc7a0ba8d3c2f2569cc8fb11d0361
address 后面的一长串字符就是你创建的账户地址,别人给你转账时需要填写这个地址。前面的 #0 是这个账户地址的本地编号,只是为了方便在本地操作账户,在区块链上没有意义。
我们现在创建的这个账户暂时还只在本地,并没有出现在区块链上,只有以下两种情况发生之后,才会真正在区块链上创建这个账户:
- 这个账户被铸币(mint),在测试网络上我们可以随意给账户里打钱,而 Libra 网络真正运行起来之后,这个环节应该类似充值,就是用法币兑换 Libra 币充到自己账户内。
- 有其他用户转账(transfer)到这个账户。
- 查询本地所有账户
libra% account list
User account index: 0, address: 3ed8e5fafae4147b2a105a0be2f81972883441cfaaadf93fc0868e7a0253c4a8, sequence number: 0
User account index: 1, address: 8337aac709a41fe6be03cad8878a0d4209740b1608f8a81566c9a7d4b95a2ec7, sequence number: 0
- 查询账户余额
libra% query balance 0
Balance is: 0
- 给账户充值
libra% account mint 0 100
>> Minting coins
Mint request submitted
- 发起转账
libra% transfer 0 1 15
>> Transferring
Transaction submitted to validator
To query for transaction status, run: query txn_acc_seq 0 0 <fetch_events=true|false>
意思是转账交易已经提交给验证节点了,但这里多说一点细节,就是此时理论上只能认为转账信息已经提交到节点,但不保证已经被执行,按我的理解,就像你寄出的快递已经被快递小哥收走,但具体送到哪儿了,还得随时用快递单号查询。(把 transfer 换成 transferb 可以实时看到转账是否已经提交到区块链,这两个命令分别相当于异步转账和同步转账)
8. 查询转账状态
libra% query txn_acc_seq 0 0 true
>> Getting committed transaction by account and sequence number
Committed transaction: SignedTransaction {
raw_txn: RawTransaction {
sender: c67ba7dce978ede151ed21f926a04733805dc7a0ba8d3c2f2569cc8fb11d0361,
sequence_number: 0,
payload: {,
transaction: peer_to_peer_transaction,
args: [
{ADDRESS: f75eadda412615ef7c662f426a9750f98f2fb9bcc2662a5ae4e140c60b40cab8},
{U64: 50000000000},
]
},
max_gas_amount: 10000,
gas_unit_price: 0,
expiration_time: 1561335836s,
},
public_key: 3fc7ea1e028f23fb926baac4c45ef92ecba1d1e7f5ad1497538d51c2b82a4574,
signature: Signature( R: CompressedEdwardsY: [243, 71, 157, 237, 123, 23, 132, 35, 242, 52, 33, 12, 210, 62, 10, 68, 199, 164, 214, 52, 129, 176, 183, 100, 138, 188, 55, 92, 209, 92, 71, 245], s: Scalar{
bytes: [198, 195, 254, 221, 249, 125, 10, 208, 109, 123, 82, 11, 187, 122, 6, 109, 189, 169, 40, 73, 97, 139, 106, 79, 2, 128, 242, 82, 150, 243, 115, 5],
} ),
}
Events:
ContractEvent { access_path: AccessPath { address: c67ba7dce978ede151ed21f926a04733805dc7a0ba8d3c2f2569cc8fb11d0361, type: Resource, hash: "217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97", suffix: "/sent_events_count/" } , index: 0, event_data: AccountEvent { account: f75eadda412615ef7c662f426a9750f98f2fb9bcc2662a5ae4e140c60b40cab8, amount: 50000000000 } }
ContractEvent { access_path: AccessPath { address: f75eadda412615ef7c662f426a9750f98f2fb9bcc2662a5ae4e140c60b40cab8, type: Resource, hash: "217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97", suffix: "/received_events_count/" } , index: 0, event_data: AccountEvent { account: c67ba7dce978ede151ed21f926a04733805dc7a0ba8d3c2f2569cc8fb11d0361, amount: 50000000000 } }