Michelson#

Michelson is the default language to write smart contracts on the Tezos blockchain. You can find the language reference here.

Michelson is a stack machine language. Here is an example of a Michelson contract deployed on the mainnet:

parameter (pair (option %admin (list address))
(pair (string %oldhash) (string %newhash)));
storage (pair (list %admin address) (string %hash));
code { { UNPAIR ;
UNPAIR ;
DIP { UNPAIR @oldhash @newhash } ;
DIP { DIP { DIP { UNPAIR @storedadmin @storedhash } } } } ;
SWAP ;
{ DIP { DIP { DIP { SWAP } } } } ;
{ DIP { DIP { SWAP } } } ;
DIP { SWAP } ;
{ DIP { DIP { DIP { SWAP } } } } ;
{ DIP { DIP { SWAP ; DUP ; DIP { SWAP } } } } ;
ASSERT_CMPEQ ;
SENDER ;
SWAP ;
{ DIP { DIP { PUSH @admin bool False } } } ;
ITER { DIP { DUP } ; CMPEQ ; SWAP ; DIP { OR @admin } } ;
DROP ;
ASSERT ;
IF_NONE {} { DIP { DROP } } ;
NIL operation ;
{ DIP { PAIR %admin %hash } ; PAIR %op } }

The contract is available at the address KT1Gbu1Gm2U47Pmq9VP7ZMy3ZLKecodquAh4

Register languages#

A smart contract is a public object. As such it is required to convey confidence in the business process it implements. It is then suggested to use register languages which make the code easier to read, write and verify.

Several register languages are available and listed here. They compile contracts to Michelson.

Archetype#

In the DApps presented here we are using Archetype, a high-level language to develop Smart Contracts on the Tezos blockchain, with all Michelson features, plus exclusive features (new types, state machine design, ...) to ease development, tests and formal verification.

For example, below is the Archetype version of the above contract:

archetype c3n(admins : list<address>, hash : bytes)
entry register (newadmins : option<list<address>>,
oldhash : bytes,
newhash : bytes) {
require {
r1: oldhash = hash;
r2: contains(admins, caller);
}
effect {
hash := newhash;
match newadmins with
| some(nadmins) -> admins := nadmins
| none -> ()
end
}
}

Completium provides a convenient set of contract templates to start your project from. Learn the Archetype language with a eight steps online tutorial:

Docusaurus with Keytar