Skip to main content

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.