How to create a smart contract using Ethereum How to conduct a smart contract audit and why it's needed
Tip

9 programming languages for smart contract development

There are languages expressly for smart contract development, but you can also use general-purpose languages like C++ and Java. Here's how they differ, and advice on how to choose.

Smart contract programming languages allow developers to craft special programs for transferring digital assets in response to specific conditions. These smart contracts typically run on top of a blockchain to automate asset exchanges without the need for intermediaries.

One of the first smart contract languages was the Bitcoin Scripting Language. It is useful for ensuring parties get paid and for exchanging digital currency during a Bitcoin sale. However, it is not practical for more complex transactions.

Over the years, new smart contract programming languages such as Solidity, Vyper and Yul emerged specifically for writing more sophisticated applications. In addition, developers have created frameworks for executing smart contract programs written in legacy programming languages such as Java, JavaScript and C++. Developers should consider their programming experience and target platform when choosing the most appropriate language for a project.

What to look for in a smart contract language

Sanjiv Maewall, CTO of blockchain and digital assets at Deloitte Consulting, suggests developers assess characteristics such as security features, execution performance, developer community support, available tools and the relative ease of learning a language. Doing so can ensure that the language they choose provides a comprehensive, secure and efficient smart contract development environment.

"Familiarity with other languages additionally aids in picking up new smart contract languages rather quickly and allows for existing best practices to also be retained in the smart contract domain," Maewall said. Previous programming experience can also make it easier to understand important concepts in smart contract development. Knowledge of object-oriented programming, error handling and testing leads to more secure, reliable and efficient smart contracts.

Nicko Guyer, Hyperledger FireFly community lead and senior full stack engineer at Kaleido, a vendor of blockchain tools and platforms, recommends developers determine the type of blockchain they plan to use before picking a language. The blockchain should be selected based on the requirements of the particular project.

Even if the best language ends up being an unfamiliar one, you can probably get up and running quickly, particularly if you have prior programming experience. "If the best answer for your project is a language you don't know, don't be afraid to learn something new," Guyer said. "It's probably not as hard as you might think."

It is also important to consider how the industry is evolving. Mrinal Manohar, co-founder and CEO at Casper Labs, a blockchain platform and service provider, observed that smart contracts were traditionally written in Solidity. But new standards like WebAssembly (Wasm), a virtual machine that can improve the performance of web applications, allow developers to write smart contracts in more mainstream languages like JavaScript, TypeScript and Python. It may also be helpful to look for a software development kit that supports features that run on top of your favorite programming language.

Here are nine smart contract languages that merit serious consideration.

1. C++

C++ is one of the oldest development languages on the list. It was introduced by Bjarne Stroustrup in 1983 to add object-oriented features to the C programming language. It is also a compiled language, which makes it perform well, but the compilation process adds an extra step to the development process. C++ is supported by popular blockchain projects, including EOS, Stellar and Ripple. It can also be compiled into Wasm code. One concern is that C++ is not a memory-safe language, which can result in security issues arising from how a program uses memory. It also can result in longer programs than some of the newer smart contract-specific languages.

2. Clarity

Clarity is a newer smart contract programming language introduced for the Stacks blockchain. It employs a framework for writing decentralized applications (dApps) that combine digital assets, data and identity in new ways. One novel feature is that Clarity is a non-Turing-complete programming language, which means it can't simulate every function of a Turing machine (a mathematical model of computation). Although Turing-complete languages allow greater flexibility, they can also be compromised by various smart contract hacks. Clarity's non-Turing-complete approach also makes it easier to perform a more thorough static analysis to identify security issues before deploying new smart contract apps. Clarity apps are also interpreted rather than compiled, which can make it easier to find and fix bugs after deploying an app.

3. Java

James Gosling developed the Java programming language in the early 1990s as a replacement for C++. One of its most essential features was the ability to write once and run anywhere. A key innovation was a just-in-time compiler that allows Java applications to run on different processes and operating systems. Java can be used to write smart contracts on Corda, Ethereum, Hyperledger Fabric, IBM Blockchain and Neo. It has a large development community and a significant ecosystem of open source components.

4. JavaScript

JavaScript is one of the most popular programming languages for developing web application front ends. It is considered easy to learn and has an extensive open source community, which helps developers get started quickly. Despite the word "Java" in its name, JavaScript is an entirely different language introduced by Netscape in the mid-1990s. Many of the most popular blockchain platforms support it, including Ethereum, Hyperledger Fabric, Neo, Polkadot and Solana. It's a good choice for developing front ends for decentralized apps. For example, the web3.js Ethereum JavaScript API includes libraries for connecting front ends to Ethereum blockchain nodes using HTTP, IPC or WebSocket calls. The ethers.js library provides a basic wallet implementation in JavaScript.

5. Python

Guido van Rossum created the Python programming language in the early 1990s. It supports a variety of application development concepts, such as object-oriented programming and structured programming. Users can employ modules to add functionality to existing apps. Python is one of the most popular languages for developing AI apps. One of its top benefits for smart contract developers is ease of use. However, it is an interpreted language, which can slow performance compared to other languages. Blockchain platforms that support Python include Ethereum, Hyperledger Fabric, Steem and Neo.

6. Rust

Graydon Hoare introduced Rust in 2006 to fix some of the memory bugs plaguing C and C++. Like the other languages on this list, it is designed for writing compact and fast apps that can run on everything from embedded systems to high-performance computers. Rust has grown into one of the most popular development languages for writing back-end applications. It's also a good choice for writing highly scalable and fast-performing smart contract applications. However, it can be more complicated to develop on top of Rust compared to languages like JavaScript, Python or smart contract-specific languages. Some of the blockchain platforms that support Rust apps include Aleo, Cosmos, OpenEthereum, Polkadot, Solana and Stacks 2.0.

7. Solidity

Solidity is hands down the most popular smart contract programming language. It was introduced by Ethereum founder Gavin Wood in 2014 and later enhanced by a team at the Ethereum project. It runs on some of the most popular blockchain platforms, including Avalanche, Binance, Counterparty, Ethereum, Tron, Hedera Hashgraph and Polygon. It is based on JavaScript syntax, which can make it easier to learn (see Figure). Another key advantage is its large community of smart contract developers that can help developers master the basics of writing dApps. That said, it comes with several limitations and challenges that some of the newer smart contract languages are designed to mitigate. For example, in 2016, Solidity was blamed for a security vulnerability that enabled an attack on one of the first decentralized autonomous organizations, a popular blockchain-based management structure.

Solidity software development lifecycle.
Figure. Solidity software development lifecycle on the Ethereum blockchain network.

8. Vyper

Vyper is a newer smart contract programming language that is similar to Python. It enables developers to create smart contract apps that run on top of Ethereum, which provides broad support for dApps. One key innovation is a focus on readability and auditability in smart contract development, which can make it easier to find bugs and help developers identify other problems sooner in the development process. A downside compared to Solidity is that Vyper supports fewer features, which improves security but can also limit functionality. Vyper also does not support object-oriented concepts like inheritance, which can slow development but also improve security.

9. Yul and Yul+

Yul is another smart contract programming language that is meant to improve performance and lower transaction costs compared to Solidity. Yul+ is a variant with features intended to make smart contract development more efficient; it also introduces new operators for describing complex smart contract concepts more efficiently. Developers must compile Yul and Yul+ apps, which can add development overhead and make it harder to identify problems after the apps have been compiled. However, the language itself is designed to be easier to read and understand before compilation. One purported benefit is better fine-grained control over how application processes drive fees for executing smart contracts. Yul apps can also complement Solidity to improve application development speed and flexibility.

Dig Deeper on Application development and design

Software Quality
Cloud Computing
TheServerSide.com
Close