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:
PascaLIGO, a syntax inspired by Pascal which provides an imperative developer experience.
CameLIGO, an OCaml inspired syntax that allows you to write in a functional style.
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.
type storage is inttype parameter isIncrement of int| Decrement of int| Resettype return is list (operation) * storagefunction main (const action : parameter; const store : storage) : return is((nil : list (operation)),case action ofIncrement (n) -> store + n| Decrement (n) -> store - n| Reset -> 0end)
This LIGO contract accepts the following LIGO expressions:
Reset. Those serve as
Runnable code snippets & exercises
Some of the sections in this documentation will include runnable code snippets and exercises. 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:
Solutions to exercises can be found e.g. here:
Running snippets / exercise solutions
In certain cases it makes sense to be able to run/evaluate the given snippet or a solution, usually there'll be an example command which you can use, such as:
ligo evaluate-value -s pascaligo gitlab-pages/docs/language-basics/src/variables-and-constants/const.ligo age# Outputs: 25