DEV Community

Radix
Radix

Posted on

Introducing the Radix Command Line Interface (CLI) - Internal Hackathon Winner!

Radix Command Line Interface (CLI)

A key focus at Radix is ensuring that the platform is easy for developers to build upon. As such, for the inaugural internal Hackathon project, James and I decided to build a Command Line Interface (CLI) which can be used to interact with the Radix ledger.

What is it?

We built a CLI which allows users to perform simple functions, such as checking their account balance and making transactions. Design-wise, we focused on creating a tool which follows the UNIX tools philosophy: create simple input/output programs then use the magic of UNIX pipes (“|”) to “stitch” up multiple programs together. This keeps functionality compact and allows a user to leverage existing, well-known tools. The equivalent in the web world are microservices.

How did it go?

After a couple of hours of Java hacking, some DevOps magic from James and more than a couple of shots of rum, we managed to create a simple tool which could read and write transactions asynchronously on a Radix Ledger.

Here’s a simple example showing how to read messages sent to my address:

$ radcli get messages
{ “from”: “

” “to”: “” “msg”: “Whatsup!” }
{ “from”: “” “to”: “” “msg”: “Josh, where are you?!” }
{ “from”: “” “to”: “” “msg”: “Yo!” }

Now if I want to search my messages for “Josh”, I can just utilize grep, a ubiquitous existing command line utility which is used to search through data:

$ radcli get messages | grep Josh
{ “from”: “

” “to”: “” “msg”: “Josh, where are you?!” }

The power of pipes!‍

Off-Ledger Smart Contracts‍

As a final example in the Hackathon we presented how a simple CLI paired with pipes could create quite powerful off-ledger “smart contracts”

Here’s an automated payment chain:

$ export SAVINGS_PERCENTAGE=0.10
$ export SAVINGS_ADDRESS=

$ radcli get transfers | jq --unbuffered -r .amount | awk -v percent="$SAVINGS_PERCENTAGE" '{print "-c \"print " percent " * " $1 "\""; system("") }' | xargs -L1 python | awk -v tok=’radcli nativetoken’ -v address="$SAVINGS_ADDRESS" '{print "send
tokens " $1 " " tok " to " address; system("") }' | xargs -L1 radcli

In the above example, Sophie would like to save 10% of every payment that comes into her day-to-day wallet and creates an automated payment chain which instructs this 10% to be sent to her savings wallet. When Sophie receives a payment £10, £1 (10%) is automatically sent to her savings wallet without any need for further intervention from Sophie.

Finally, here’s a faucet service which transfers 10 XRD to anyone who sends a message to my address:

$ radcli get messages | jq --unbuffered -r .from | grep
--line-buffered -v ‘radcli myaddr’ | awk -v tok=’radcli nativetoken’ '{print "send tokens 10 " tok " to " $1; system("") }' | xargs -L1 radcli

By keeping the CLI simple and useable with pipes, more sophisticated functionality becomes possible without any extra work, almost like magic!

But most importantly, we were both delighted to be awarded first place by our colleagues for our work!

Note: As the CLI is built to interact with the internal betanet, we will open-source it only after the public betanet is live.

Have questions? Message me or James on the Radix discord group (https://discord.gg/CZ6WMfW), or you can ask them in our telegram channel (https://t.me/radix_dlt) as well.

Subscribe to our mailing list to get notified when we major milestones - https://radixdlt.typeform.com/to/nyKvMV?source=DecentraSign

Original blog post, including pics from the presentation - https://www.radixdlt.com/post/introducing-the-radix-command-line-interface-cli-based-on-the-unix-tools-philosophy

Join The Radix Community

Telegram for general chat
​Discord for developers chat
​Reddit for general discussion
Forum for technical discussion
Twitter for announcements
​Email newsletter for weekly updates
Mail to hello@radixdlt.com for general enquiries

Top comments (0)