A Noob’s Guide to Facebook’s New Cryptocurrency Platform – Libra

With all the hype behind the latest “cryptocurrency” in the news, I thought it would be fun to fire up the blockchain and figure out how it all works. For some historical perspective, As of earlier this week, Facebook announced it’s intent to enter the cryptocurrency arena with a wallet called “Calibra” which is built to interact with the “Libra” environment. The Libra currency is identified by three wavy lines in front of the amount, replacing the dollar sign, as seen in this photo:

Graphic:Facebook

What you need to understand is that Facebook is not developing Libra, they are developing the Calibra wallet, which interacts with the Libra blockchain or environment. This, much like any blockchain solution, I assume, is done through sending data to an address on the blockchain, where that data will cause effects, whether that be a smart contract, or exchanging currency, or countless other things. The Libra blockchain is built in a new language called Move.

I don’t yet really understand exactly what Libra is, so I intend to build up my environment to interact with the Libra testnet and figure out how it works. This should give me a better idea of how this massive “Facebook Crytocurrency” is going to work. The first thing that I am going to do is to clone the Libra Core repository.

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

Now that the repository is present, the next step is to run the setup script which should install some necessary dependencies as identified by the My First Transaction post on the Libra Developers site:

  • Installs rustup — rustup is an installer for the Rust programming language, which Libra Core is implemented in.
  • Installs the required versions of the rust-toolchain.
  • Installs CMake — to manage the build process.
  • Installs protoc — a compiler for protocol buffers.
  • Installs Go — for building protocol buffers.
cd libra
./scripts/dev_setup.sh

So we have got a couple errors, but after some troubleshooting, I think that I’ve got it fixed up. If you are choosing to follow along, or have run into problems on your own, do not forget to refer back to the Troubleshooting page for help.

./scripts/cli/start_cli_testnet.sh

I ran into a couple issues, the first one came with the message below. I am using a server that functions as nothing but a media server for my home, so it is not development-focused. If you are using a platform such as that, you may run into similar issues. I had to install gcc, rust, go, cmake, along with modifying the structure of my filesystem by quite a bit. If you run into issues or errors, they will be displayed in a manner such as this:

Once the client successfully connects to the testnet, you will see the following output, which gives some good syntax hints for how to actually interact with the environment:

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%

The first thing we will do is check and see what accounts are already associated with this client using the “account la” command.

Thankfully, we have no accounts already associated. So we shall create one. This is something that Facebook, I am guessing, will automatically do for each user as their actual Facebook accounts are created, which means that if the users are not controlling their private keys, they are not really in control of their funds, but I digress. Based on the options available, it looks like we can create an account using the “account c” command:

If you are paying attention, the account is referenced as “account #0” and then displays a long string of numbers afterwards. Initially, I thought that this number was the public key, however, after referencing the developer’s documentation, I found that that number was only an index number that the CLI references and not any key at all. Apparently, neither the public or private key is created until currency is either minted to that account or transferred into it from a different account. So let’s mint some coins:

libra% account mint 0 110
>> Minting coins
Mint request submitted

According to the dev documentation, that only means that the mint request has been sent to the mempool: “Note that when the request is submitted, it means that it has been added to the mempool (of a validator node on testnet) successfully. It does not necessarily imply that it will be successfully completed. Later, we will query the account balance to confirm if minting was successful. If your account mint command did not submit your request successfully, refer to Troubleshooting

As the documentation states, we might not have a successful mint operation, but we can check our balance using the following command:

libra% query balance 0
Balance is: 110

Once you shutdown the client, the data is lost, so I closed down my client and started it back up again. I created two new accounts and immediately minted 1337 coins to account 0, but encountered an anomaly:

We have only minted 1337 coins, and it lists a balance of 1447. So we know that even though after I shut my client down and started it back up, I queried the accounts available and it said there were none, but they account did persist, as did it’s balance.

Using the Move syntax we can also query events, at this time, it is only able to query sent and received coins. I sent this query to see if the “mint” operation was qualified as a “receive” transaction.

>> Getting events by account and event type.
No events returned

Since I had created a second account, I transferred the original 110 coins to the account at index 1, so I can query that event:

libra% transfer 0 1 110
>> Transferring
Transaction submitted to validator
To query for transaction status, run: query txn_acc_seq 0 0 <fetch_events=true|false>

And to see the actual transaction:

libra% query txn_acc_seq 0 0 true
>> Getting committed transaction by account and sequence number
Committed transaction: SignedTransaction { 
 raw_txn: RawTransaction { 
	sender: 38870d781faff697172f2cb5a32912a2337152a0b9b7e4f60d44926617787fb7, 
	sequence_number: 0, 
	payload: {, 
		transaction: peer_to_peer_transaction, 
		args: [ 
			{ADDRESS: b564f207568bc39bc3a07e51e93fac16f1f275bef50181c17bfe9ca5316a77cb},
			{U64: 110000000}, 
		]
	}, 
	max_gas_amount: 10000, 
	gas_unit_price: 0, 
	expiration_time: 1560966850s, 
}, 
 public_key: d7f462d6f40d823f84fd467fd2c8213f98c90027787f062d7e9d5696a7369b0f, 
 signature: Signature( R: CompressedEdwardsY: [61, 108, 150, 67, 171, 149, 171, 65, 7, 18, 91, 157, 188, 43, 109, 182, 14, 223, 158, 3, 235, 155, 116, 82, 227, 11, 205, 175, 88, 118, 39, 63], s: Scalar{
	bytes: [254, 122, 215, 201, 62, 202, 165, 193, 137, 10, 2, 136, 220, 48, 179, 97, 42, 252, 5, 140, 139, 215, 171, 104, 171, 239, 113, 126, 252, 115, 233, 10],
} ), 
 }
Events: 
ContractEvent { access_path: AccessPath { address: 38870d781faff697172f2cb5a32912a2337152a0b9b7e4f60d44926617787fb7, type: Resource, hash: "217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97", suffix: "/sent_events_count/" } , index: 0, event_data: AccountEvent { account: b564f207568bc39bc3a07e51e93fac16f1f275bef50181c17bfe9ca5316a77cb, amount: 110000000 } }
ContractEvent { access_path: AccessPath { address: b564f207568bc39bc3a07e51e93fac16f1f275bef50181c17bfe9ca5316a77cb, type: Resource, hash: "217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97", suffix: "/received_events_count/" } , index: 0, event_data: AccountEvent { account: 38870d781faff697172f2cb5a32912a2337152a0b9b7e4f60d44926617787fb7, amount: 110000000 } }

So in this transaction, we now can see the public key and transaction ID and contract hash.

Libra seems like a run-of-the-mill blockchain, but the way that Facebook interacts with the environment and the code at their address once the production chain is released will be the impressive part once it is released. If you are interested in playing with the Libra testnet, check out My First Transaction.

Leave a Reply

Your email address will not be published. Required fields are marked *