Elements code tutorial

Application development on Elements

In this part of the tutorial we will learn how to develop applications on top of Elements using RPC.

Examples are provided in Python, C#, Ruby, Node.js, Go, Perl, and Java. The Python and C# examples are expanded to cover web applications using Flask and the .NET MVC frameworks. The examples can easily be amended to work against Bitcoin or a codebase based upon Elements, such as Liquid, by amending the rpc settings in your config file.

In the main sections of the tutorial we used a terminal to send commands to the Elements client (elements-cli), which in turn would issue RPC (Remote Procedure Call) commands to the Elements daemon (elementsd). This configuration will be familiar to those who develop for Bitcoin, which the Elements code is based upon.

The communication between daemon and client is possible because, when started in server mode, elementsd initiates an http server and listens for requests being made to it on a port specified in the associated elements.conf file.

Requests to the daemon are made by posting JSON formatted data to the http server port that the daemon is listening on. The request is processed and the results are returned as JSON formatted data.

Verification details of the credentials needed to make these calls is also stored in the config file. This is how elements-cli and elementsd were able to communicate in the previous tutorial code, they both shared the same config file and therefore the client could satisfy the authentication checks of the daemon.

Take a look in the elements.conf file in $HOME/elementsdir1 that we created during the tutorial and notice the rpc related settings.

We can use the same authentication details and port number to send requests to the Elements daemon ourselves by using a programming language to make the RPC calls and process the returned results.

We’ll use Python for our first example, but any language that can make and receive http requests can be used. Basic examples are also provided for the following languages: C#, Ruby, Node.js, Go, Perl, and Java.

Next: Desktop application example in Python