February 2, 2024

The Programming Languages Behind Cardano On-Chain Code

EMURGO

The-Programming-Languages-Behind-Cardano-On-Chain-Code-1

In a previous blog, we discussed the specialized role of the on-chain Cardano blockchain developer responsible for writing on-chain code for a Cardano dApp that gets deployed to the blockchain and executed by the nodes in the network. To write this on-chain code, Cardano developers can use different programming languages.

The Cardano network was made to be versatile and inclusive. It chose Haskell as its core language, but at the same time, it created the tools to open the network for any alternative. The push is to enable various possible solutions while ensuring the same level of security.

This has created a very special ecosystem for Cardano, one where there are multiple alternatives to writing on-chain code without compromising the security of the blockchain. This is virtually unheard of on other protocols.

Each of these languages is an alternative to the on-chain code which compiles to Plutus Core and this means each of these alternatives benefits from the Plutus Virtual Machine that interprets Plutus Core. It is important to note that only PlutusTx actually has a formally verified compiler.

Other languages like Aiken are also widely used and tested and is used for many of the most popular dApps in the Cardano ecosystem.

As such, it’s a matter of preference which one to use and not so much about properties that make them better than each other. 

Let’s look at the different programming languages for Cardano on-chain code below.

Cardano on-chain code programming languages
The Programming Languages Behind Cardano On Chain Code 2

PlutusTx

One way to write smart contracts on the list is PlutusTx, which is a compiler plugin for the Glasgow Haskell Compiler (the mainstream Haskell compiler), with the main language being in Haskell.

It’s the supported method to write on-chain code by the team at IOG. It’s a domain-specific language that was created based on Haskell and as such mirrors the syntax of its parent language almost 1-to-1.

PlutusTx is the main method that is backed by the team at IOG and support from the other founding entities. It has ample support in some areas, but also lacks comprehensive documentation and resources in the Cardano ecosystem compared to other alternatives such as Aiken. It has already received a major overhaul after the Vasil hard fork and the introduction of PlutusV2.  

In the future, this pattern is expected to continue. The core developers will improve the features of Plutus and other teams will have to catch up with their changes. This is why it’s recommended to learn Plutus for everyone looking to enter Cardano development. 

Aiken

Aiken is one of the alternatives to PlutusTx. 

Aiken is inspired by some of the most familiar languages for developers and has quickly evolved into a friendly tool for Cardano developers.

It was made in response to a need for a functional programming language in Cardano and enables developers to build dApps quickly and easily.

Born from TxPipe and with support from the Cardano Foundation, Aiken has been adopted by the community as a popular smart contract language. 

It is a very popular alternative to the original PlutusTx with its clear documentation, end-to-end examples, and vibrant community. There is a sizable pool of developers who understand functional programming with a background in TypeScript, Python, Java, and Go, which can quickly onboard to the Aiken way of doing things. Aiken has allowed them to enter the Cardano ecosystem using a language that uses some familiar concepts for them.

Additionally, Aiken provides some gains on execution units which directly correlate to the number of steps and memory that a contract can do on-chain. There are fewer steps to finish an instruction in Aiken which makes for more efficient validators. It’s the size that determines the fee amount, so any gains on that area make transactions and therefore by extension dApps cheaper to use. 

Helios

The Helios language is a Javascript/Typescript SDK alternative for on-chain code on Cardano. 

It was created to onboard web developers onto Cardano. The Javascript/Typescript ecosystem is among the largest among programmers and Helios is a good option for these people.

The Helios toolkit also has the distinction of working for both on-chain and off-chain code! The creators of Helios have developed a version for each of the sides of a Cardano dApp. So, developers no longer need to use one type of language for on-chain and then switch to a different one for off-chain. 

The Helios language can also be used to calculate and manage Cardano assets during a transaction. This makes it one of the most versatile alternatives in the Cardano ecosystem for programmers of all backgrounds. 

Opshin

Opshin is a language that uses 100% valid Python code for on-chain logic on Cardano. 

It’s the main alternative for those looking to build on the network that have a background in Python. There is a large community of data analysts that come from Python that can benefit from this alternative. 

The language is easy to install and start to use for those familiar with Python. It supports both imperative and functional paradigms without compromising the core design of Cardano smart contracts.

Programming-Languages-Behind-Cardano-On-Chain-Code-3

Plu-ts

Plu-ts developed by Harmonic Labs is another Typescript alternative for on-chain code. 

The implementation of the language also provides tools to write off-chain code, so it allows developers the ability to use the same syntax for both portions of the Cardano dApp.

Additionally, Plu-ts aims to give developers more control over the compiled code. This means the size of a smart contract can be optimized to make it cheaper for the user. This means dApp developers can further push Plu-ts to make their platforms cheaper to use. 

Plutarch

Plutarch is another domain-specific language albeit only for on-chain code based on Haskell. It is considered a higher level of abstraction when related to Haskell, which gives developers ways to write highly efficient smart contracts. But these are harder to reason about due to the level of abstraction in Plutarch. 

The main objective of it is to optimize the size of a validator to make transactions as cheap as possible. At the moment, Plutarch is the language that proves the smallest validators for Cardano dApps.

This has made Plutarch the first choice for dApps that want to optimize their fees as much as possible. It’s an advanced option for developers proficient with Haskell, as it relies more on the core features of its parent language than other alternatives. For this reason, it’s not very beginner-friendly, but certainly a viable choice for Haskell veterans. 

There we have an almost comprehensive list of all the different ways to write on-chain code on Cardano. Except for PlutusTx, all the other projects were created by the community and are supported by independent teams. 

All of them share the same core security properties and don’t compromise Cardano in any way. This means that the choice of which one to use comes from the experience of a developer team. All of the choices are 100% viable and each is being improved constantly by the Cardano community.          

Follow EMURGO for X for Cardano info

EMURGO is a global blockchain technology company that supports builders, organizations, and others to adopt Cardano for Web3 products and services.

To receive updates on Cardano and EMURGO, follow EMURGO on X (formerly Twitter) for details about the latest announcements, Cardano education courses, project funding, Cardano-related events, and more.

About EMURGO

Disclaimer 

You should not construe any such information or other material as legal, tax, investment, financial, or other advice. Nothing contained herein shall constitute a solicitation, recommendation, endorsement, or offer by EMURGO to invest.

Related articles