Nexa Programming Language (NPL): Smart Contracts in Kotlin

Nexa Programming Language (NPL) is a domain-specific language and compiler for writing Nexa smart contracts. Each smart contract includes rules that decide how coins can be spent. NPL lets developers write smart contracts in Kotlin, and the compiler converts them into scripts that can run on the Nexa network.

Kotlin is a multiplatform language that lets you run a single codebase across multiple platforms and operating systems. It is also the preferred programming language of giants such as Google for developing applications on Android.

A single programming language that works across platforms benefits developers and users. We are excited to introduce NPL as the preferred language for writing smart contracts on Nexa.

Nexa Programming Language (NPL):
https://gitlab.com/nexa/npl

Benefits of Nexa Programming Language

Every smart contract is built from a set of rules. It can offer several ways to be spent, for example one that pays a seller and one that refunds the buyer after a deadline. Each rule is an independent way to spend the contract, and if any single rule’s script succeeds, the funds unlock.

Nexa script runs on a stack machine, and arranging that stack by hand is a difficult task. With NPL, the developer describes what must be checked, and the compiler handles the order of operations and the stack.

A rule’s script is written in NSL (the Nexa Scripting Language). NSL is dependency-based: variables are read-only and the compiler determines execution order from data dependencies, so you write straight-line logic and let it figure out the stack.

One contract can serve many users. The details of every deal, such as who is involved, how much and by when, can be filled in when coins are sent to the contract. The contract itself stays the same, and with this architecture it can be reused many times.

The test environment is where you iterate on the NSL logic, run it against the script machine, and verify each rule behaves correctly. All contracts should be compiled and tested before they go live, and only the finished result should be used in an application.

Existing Contracts

The Nexa Programming Language repository already includes example contracts with tests. These include a demonstration sale with a timeout refund, price and sports prediction contracts settled by a trusted oracle, the Nexa Warriors battle card contracts, and a time-lock vault.

Some NPL use cases are still in active development, and details may change. These are just the first steps and examples, and they are meant to expand with more challenging and exciting use cases.

To Wrap Up

Nexa Programming Language (NPL) is a big step towards improving Nexa’s smart contract capabilities and developer experience. It is also a fully open-source Kotlin library under the MIT license, open for everyone to use and contribute to.

More projects and examples leveraging NPL are underway. We hope NPL will be a great addition to the recently introduced and updated Build On Nexa (BON) website, with its developer resources and AI skills.

If you need any help or have any questions, make sure to join our community groups. The team is always ready to help.

​

Nexa Discord: https://discord.nexa.org
Nexa Telegram: https://t.me/nexacoin
Group for Developers: https://t.me/nexa_dev