Fun And Games With The Libra Testnet

The Roman libra is about 329 grams. These, however, are denarii.

Summary

This article walks through some of the things you can do with the Libra command line interface and even gives you some tools to automate submitting commands to it. They’re tools I’ve used in the past to automate CLIs that don’t have an API to make life easier, but you will have to be familiar with Linux command prompts and a bit of bash scripting.

Back to Libra

The actual currency isn’t live yet, but there are a code base and a testnet, which gives you plenty of opportunities to play about. If like me, you use a Ubuntu Linux box, you can get started fairly quickly by opening up a terminal (Ctrl+Alt+T) and entering the following:

$ git clone https://github.com/libra/libra.git
$ cd libra
$ ./scripts/dev_setup.sh
$ ./scripts/cli/start_cli_testnet.sh

Addresses and Seeds

One of the neat things about the CLI is that you don’t need to use those long strings that represent the blockchain addresses. If you create five addresses, they are referenced with an index, i.e. 0 through to 4.

libra% a w seed.txt
correct horse battery staple flight banana car gumboot plug bread streamer handle ice blind letter potato pizza foot dish elbow can chair carpet spray;5

Automatically driving the CLI

Fortunately, Linux has this excellent tool called xdotool. Simply open up a new terminal (you’re going to need this shortly anyway) and install it with:

$ sudo apt-get update$ sudo apt-get install xdotool
$ xdotool search --name "/libra"
$ xdotool windowmove 67108874 0 0
$ xdotool windowactivate 67108874; sleep 1; xdotool type 'a m 0 100'; xdotool key KP_Enter;

Making a Mint

In the examples that follow I use bash, because it’s quick and easy, but you can equally write a Python script, for example, and call xdotool from it (e.g. using subprocess.check_output). So here’s a script that generates 100 new addresses and then tries to mint the maximum amount of coins for them:

#!/bin/bash
xdotool windowactivate 67108874 # change this to your terminal ID
for i in {0..99}
do
sleep 1
xdotool type "a c"
xdotool key KP_Enter;
sleep 1
xdotool type "a m $i 10000000000000"
xdotool key KP_Enter;
sleep 30
done

Move Your Money

How about we try to move our fortune into the first address? After all, it’s so much nicer to have one big pile rather than a lot of little ones:

#!/bin/bash
xdotool windowactivate 67108874 # change this to your terminal ID
for i in {1..99}
do
sleep 1
xdotool type "tb $i 0 10000000000000"
xdotool key KP_Enter;
sleep 5
done
libra% q b 0
Balance is: 10000000000000.000000
libra% q b 0
Balance is: 10000000009300.000000

Microlibras and Libras

Now that’s an interesting number. Anyone who’s worked down at the bits and bytes level will instantly recognize that it’s 2⁶⁴ -1 / 1000000.

  • the size of the data field is 64 bits.

In Conclusion

I’ve certainly had an enjoyable wander through the new world of Facebook’s Libra testnet, and I hope you have too.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Keir Finlow-Bates

Keir Finlow-Bates

593 Followers

CEO and co-founder of Chainfrog Oy, a Finnish startup researching and developing advanced blockchain technologies.