Micro Focus is now part of OpenText. Learn more >

You are here

You are here

23 blockchain languages driving the future of programming

public://pictures/Peter.Wayner.jpg
Peter Wayner Freelance writer
 

Most of the hype around blockchain comes from the cryptocurrencies built upon them, their stunning rise in value, and their precipitous fall.

Wealth has a way of capturing our attention. But underneath the dreams of outrageous fortune are elaborate new programming languages that are changing how we're thinking about giving instructions to computers.

The money may come and go, but cryptocurrencies are already disrupting programming. When the stakes are high, ensuring that the code runs correctly is more important than ever—and the language creators are simplifying the syntax, streamlining the logic, and strengthening the structure to make it easier for programmers to get it right. 

Here's a primer.

Money talks—contracts matter

People get more serious about building correct and trustworthy languages when money is at stake. But in reality, all of the different cryptocurrencies are more than just money. Each transaction is actually a mini-program that executes when the money is spent. If the software runs correctly and completely—and only if it does—the money is transferred from owner to owner.

This opportunity has unleashed innovators who want to write elaborate contracts in these languages, contracts that will bind everyone involved. They want to build code that will do more than pay 10 coins to Chris; they imagine creating contracts that will enforce liens and ensure that everything is paid in full.

A smart contract for a five-year car loan, for instance, may transfer full ownership to the borrower only when 60 monthly payments are registered on the blockchain. Some even want the contract to check that all of the fees to the Department of Motor Vehicles are paid on time and the insurance has been maintained, in both cases after these facts are also recorded on the blockchain.

[ Also see: Blockchain for developers: Is it right for your application? ]

The languages behind blockchain

The programming languages used in these blockchains are pretty basic, often no more complex than the simplest code that arrived soon after the first computers were built. Bitcoin Script, for instance, has only a few permitted operations, and the data is pushed and pulled from a virtual stack. There are no higher-level constructs such as loops, a limitation to ensure that the code runs quickly to conclusion.

Programmers who want to write smart contracts or other code on the blockchain must be ready to confront different challenges. First, they must create something concise and extremely efficient, because everyone double-checking the blocks will execute it. Second, they must imagine what happens when the code is run on different nodes at different times.

The consequences for making a mistake can be terrible, because a smart criminal may figure out a way to trigger a payout. This happened with one investment group called the DAO; some estimated the hacker's take to be more than $50 million.

The simplicity of the languages has led some developers to create higher-level, more feature-rich languages that are closer to what is used for most modern code. Some of the latest options are more elaborate and must be compiled into the operations that are embedded in the blockchain.

Oldies but goodies

Not all of the languages underlying the projects are new. Other developers have wondered whether we need to create something different, and they’ve been experimenting with tweaking and limiting old, general-purpose languages that deliver the same features as newer languages while maintaining a connection to more familiar syntax. This approach can make it easier for developers to integrate their existing code with blockchains.

Serpent, for example, was one of the original languages for Ethereum; it was a low-level, assembly-like sequence of operands. The language was deprecated recently, and developers have steered away from it. Some of the code written in it may still live on in the blockchain, but it is generally referred to only for historical reasons.

Mutan is another of the original languages for Ethereum that has been set aside since 2015. It was modeled after the popular network language Go, but many of the developers who enjoyed it have since moved to Solidity.

Here are the key languages from the world of blockchains arranged in an order that roughly approximates the jump from low-level, simple languages to higher-level, more powerful ones. Some are new creations with an elaborate devotion to correctness, while others are older languages that are getting some traction, and still others are just extras that provide important support.

Bitcoin Scripting Language

The original language still controls all of the transactions on the Bitcoin blockchain. The individual operations are single bytes, and most of them perform very basic operations such as pushing a value onto the stack or adding the top two values. All the basic arithmetic and Boolean operations are supported.

The high-end operations boil complex cryptographic operations down to one byte. Opcode 169 (0xa9) will hash the input, first with the SHA-256 and then with RIPEMD-160 for extra security.

Opcode 173 (0xad) will check a digital signature to make sure that the transaction was properly authorized. If you want to lock up a coin until some moment in the future, you can ask the code to make sure the time is greater than some threshold.

Most of the code on the blockchain is pretty straightforward, merely transferring coins from the control of one public key to another. But some have created more elaborate contracts.

LLL

The acronym stands for Low-Level Lisp-Like Language. It offers a thin wrapper of parentheses-filled, Lisp-like code to cover up the basic assembly instructions that run on the Ethereum Virtual Machine.

It remains popular, unlike Serpent, because it offers able programmers access to all of the memory locations and other power hidden at the lowest levels. Adept LLL programmers claim they can produce contracts that are half the size, or even smaller, compared to higher-level languages such as Serpent, something that saves everyone in the long run. 

Vyper

This low-level language for the Ethereum chain is said to be "Pythonic," which is to say the syntax is meant to be more familiar to those who use the language Python. Even though the basic punctuation and structure will be familiar to Python programmers, large numbers of features were left out to make it easier to write very simple code that is, in theory, also very easy to understand and audit.

Many of the biggest changes are limits on the kind of clever aliasing that programmers love to do. The Vyper developers tried to eliminate the renaming and overloading that regular programmers deploy to make their code concise and—in their minds—elegant and crisp.

The Vyper team rejected these kinds of modifiers and overloading opportunities because they're also opportunities to obscure and obfuscate, two techniques that are often partners to fraud.

Simplicity

This new language was designed to leverage much of the academic work done to develop sophisticated mathematical proofs of software. The syntax was deliberately kept very simple to encourage the use of the tools for formally verifying and proving the correctness of the software. The creators like to brag that the specification for the language is so simple it can be printed on a T-shirt.

While the syntax is simple, the team has made sure to add a number of sophisticated cryptographic primitives to make it possible to build more sophisticated contracts. They encourage the development of side chains and other coins that piggyback on the Ethereum infrastructure.

Varna

The Æternity blockchain also supports Varna, a much more basic language that was inspired by the simplicity of Bitcoin Script. It is still a work in progress.

Obsidian

One of the newer languages for Ethereum lets you write code by specifying states and the transitions between them. In other words, it's similar to creating a flowchart for a workflow where the contract moves through different states of completion until all of the terms are satisfied.

The developers have also added a nice linear type system to add a belt to the suspenders. The compiler can use the types to prevent some stupid bugs caused by typos. Of course you've got to set up the type hierarchy correctly, too.

The documentation suggests that the language is still "under development" and not ready for general use.

Solidity

One of the highest-profile languages is Solidity, the standard language that can be deployed to the Ethereum blockchain. It looks much like a modern programming language such as JavaScript, and it offers curly bracket–delimited functions, objects, inheritance, and almost everything that makes the code look like Java, C, or JavaScript.

The objects you create run on the nodes maintaining the blockchain, store their internal database inside the ledger, and live on until the final value is spent by a transaction. Your code can send and receive contracts from other smart contracts, allowing fairly elaborate transactions.

Many call the language Turing-complete, a technical term that means you can write everything you might create in other major languages. In practice, Ethereum code can run only when you pay for the time on the nodes using an internal currency called "gas"—and the amount of gas you can use is strictly limited.

Many programmers joke about creating elaborate databases with complex loops, but acknowledge that it's important to limit your aspirations to data structures and calculations that can be executed in a short, bounded amount of time.

WASM

WebAssembly is a simplified-state machine designed to speed up the web by offering simple, pre-compiled code to replace JavaScript in web pages. It's also the foundation for the EOSIO blockchain contracts. The first generation of contracts tend to be written in C++ and compiled into WASM, but there are also compilers for other common languages such as Rust, Python, and Solidity.

Rholang

Developers creating smart contracts for the RChain cooperative should use Rholang, a message-passing language with a sophisticated, behavioral typing system for standardizing the contract flow. Elaborate contract terms can be negotiated and enforced through a modern type mechanism.

Contracts are specified as a collection of channels carrying messages signifying milestones in the negotiations. The channels can fork and join so sections can be expressed in parallel.

The language will be most familiar to programmers who enjoy functional languages such as Haskell.

Michelson

The Tezos blockchain is a proof-of-stake with an explicit voting mechanism for upgrading the basic exchange protocol over time. Contracts are written in Michelson, a statically typed language with strict type checking that's built around a stack. The documentation says the creators were inspired by stack-driven languages such as Forth and more functional approaches such as Scheme and meta-language (ML).

Plutus

The Cardano blockchain is another proof-of-stake approach—a way to achieve distributed consensus—with multiple layers that separate the settlement (where the money is exchanged) from the control (where the decisions in the smart contracts are made).

The contracts are written in Plutus, which bears many similarities to Haskell, the dominant language in the stack. The contract code is fully functional and strong, and static typing is enforced for data flows.

Sophia

The Æternity blockchain mixes proof-of-work with proof-of-stake and emphasizes a connection to real-world objects in the Internet of Things. Contracts and their link to the world, the so-called oracles, are written in Sophia, a strongly typed version of ML. Sophia includes blockchain-specific features such as explicit contracts data structures built into the language.

JSON

The data format isn't a language, but some of the blockchains are effectively controlled through JSON packets. Transactions in Ripple's XRP Ledger, for instance, are initiated and controlled through POSTing JSON data. You'll need to write your code to fill the fields and then POST it, but this means you can use pretty much any language and library that will make it easy to send HTTP POST messages.

Swift, PHP, Kotlin, Lua, Laravel, or Ruby

These common programming languages aren't mentioned very often in this context, but some of blockchain projects are reaching out to developers who use them by opening up the API and releasing sample code that targets the API. Ark, for instance, maintains samples that work with all of these.

There's a good chance that what you need to do doesn't require writing an actual smart contract itself. If you only need to work indirectly, you can get by with your favorite non-blockchain language.

JavaScript

While smart contracts running Ethereum are written in special languages developed to ensure correctness and completeness, some of the ancillary work can be written in JavaScript.

If you're going to be writing tools that track contracts and translate their state into nicer, human-readable websites, you'll probably want to experiment with Web3, a collection of JavaScript objects that smooth interacting with the blockchain. You can write the code that will track your contracts, keep them active with gas.

That's just the start. It's virtually impossible to list all the different blockchains with code that builds upon Node.js, a server-side platform built on Google Chrome's JavaScript Engine. Clients, middleware, and server-side code, all written in JavaScript, are everywhere.  

Containers

While most of the blockchains are deliberately separate worlds that use their own special languages, Codius is experimenting with running any code that can live in a container. The approach, which the website warns is still in beta, will work with arbitrary software that might run on any computer.

This makes development easier, but may also leave the mechanisms open to abuse and fraud. Many of the languages crafted for blockchain were designed to make auditing the code simpler to prevent the kind of errors that can lead to the loss of money, or worse.

C#

The Stratis blockchain will support .NET and C# code developed in Visual Studio, something that should appeal to programmers familiar with Microsoft standards. The smart contracts are written in C# and then wrapped with a web-based front end.

SQL

The Aergo platform relies heavily on an SQL-like language for some parts of its protocol and contracts that can be crafted using well-understood queries that run against relational database tables.

[ More from Peter Wayner: 13 programming languages defining the future of coding ]

Beyond the blockchain

Most of these languages are new, but the enabling of well-audited code built from simpler constructs is working its way back to more traditional code. The code that runs on the server and handles much of the transaction processing is often written in popular languages such as C++, Rust, Java, or Python.

Most programmers who are building smart contracts won't need to explore this system programming layer, but if you're going to be working on enhancing mining, or creating some wallets or other infrastructure, there's a good chance you'll be exploring these code bases and using these languages.

This software for the infrastructure must be developed just as carefully as any other crypto-code, and so developers are starting to ask the same questions about the underlying code as they do about the code explicitly running in the blockchain. Is the code correct? Have we checked all possible ways it can go wrong? Have we squeezed all of the possible bugs out of it? In other words, have we built it with the seriousness demanded by financial applications?

And, finally, as we head into the future, how can we squeeze the same incorruptible accuracy out of the older languages?

Keep learning

Read more articles about: App Dev & TestingApp Dev