Introduction to LIGO
LIGO is a programming language for writing Tezos smart contracts. Smart contracts are a unique domain with extreme resource constraints and even more extreme security risks. Unlike desktop, mobile, or web application development, smart contracts cannot rely on cheap CPU time and memory. All resources used by contracts are expensive, and tracked as 'gas costs'. Smart contracts often directly control money or assets, which if stolen could rack up to a large financial loss to the contracts controllers and users. Tezos smart contracts live on the blockchain forever, if there's a bug in them they can't be patched or amended. Naturally, under these conditions, it's not possible to develop smart contracts the way we're used to developing user-facing applications.
LIGO is designed with these problems in mind. The design philosophy can be described in a few bullet points:
Make a clean, simple language with no unnecessary parts.
Offer multiple familiar syntaxes so users can get up and running quickly.
Encourage people to write simple code, so that it's easy to formally verify the compiled output using a project like Mi-Cho-Coq.
Significantly reduce the risk that your smart contract will lose its balance to an avoidable exploit.
LIGO is a functional language designed to include the features you need while avoiding patterns that make formal verification hard. Most useful smart contracts can express their core functionality in under a thousand lines of code. This makes them a good target for formal methods, and what can't be easily proven can at least be extensively tested. The simplicity of LIGO also keeps its compiled output unbloated. Our hope is to have a simple, strongly typed language with a low footprint.
LIGO currently offers three syntaxes:
CameLIGO, an OCaml inspired syntax that allows you to write in a functional style.
PascaLIGO, a syntax inspired by Pascal which provides an imperative developer experience.
Let's define some LIGO contract in the three flavours above. Do not worry if it is a little confusing at first; we will explain all the syntax in the upcoming sections of the documentation.
This LIGO contract accepts the following LIGO expressions:
Reset. Those serve as
Runnable code snippets
Some of the sections in this documentation will include runnable code snippets. Sources for those are available at the LIGO GitLab repository.
For example code snippets for the Types subsection of this doc, can be found here:
In certain cases it makes sense to be able to run/evaluate the given snippet. Usually there will be an example command which you can use, such as: