Tezos Smart Contracts Example Repo

Aharon Lando
Tezos Israel
Published in
4 min readMar 18, 2021

Check it out at edu.tezos.co.il

As the Tezos ecosystem grows and develops, more projects are being deployed to the blockchain, and so does the demand for educational resources for new Tezos developers.

One of our focuses at Tezos Israel is the education and training of new developers in our local region and globally. As the ecosystem matures over time, the documentation of Tezos programming languages (Ligo, SmartPY, Michelson, etc.) will grow and become vast and easily found.

As our development team expands, and the portfolio of projects we are working on & incubating grows, it was sometimes time-consuming to train our new developers on Tezos smart contract development.

Though mostly a non-issue as everyone on our team is clever and independent, we have learned most of the work on our own. However, there is one big piece we felt was missing — besides the documentation on the different languages, we’ve had some difficulties finding very simple examples that are so useful for beginners to look at and see the subtleties of a smart-contract being built up and addressed one by one.

As mentioned, we overcame the difficulties through trial and error, and a lot of reaching out in the dark to find the exact recipe for having a new-developer’s training method that is oriented towards self-learning and exploration. When all of our developers got to a level that they can write smart-contract at all levels, we started to think about how we can make this process easier for the next generation of developers, which is, as I’ve mentioned, one of our goals. Seeing this lack in very simple, well-constructed examples of code, we’ve decided to build a new project — a smart-contract examples repository, with examples ranging from as simple as a contract that outputs “Hello world” when called, to the intimidating FA2 non-fungible-token contract construction, with intermediate examples of all structure types, conditional contracts, signed contracts, etc.

All the contract examples are also connected to a front-end using taquito, which allows the developer to see how simple DAPPs are built, and there are tests and migration files ready to use for each contract.

The following is a demonstration of one of the very simple examples we’ve built — a “calculator”, taking two integers and applying one of add, subtract, multiply and divide functions on them. This demonstrates the use of integers, with one condition (inequality) and the proper use and syntax of a “failwith” command (although not necessary here because of the built-in “DIV by 0” error that’s being automatically generated when compiling a division into Michelson, but added anyway for the sake of learning).

This is the camelLIGO version of the contract. Currently, all existing contracts are written in the three LIGO syntaxes, with the aim of continuing in all other languages, including Michelson versions of the contracts.

camelLIGO Calculator smart-contract example code

This very simple code allows the observer to see how variants are written, some simple typing, variant tuple access, a very basic condition, the “failwith” correct syntax, and pattern matching. Having the same contract in all three LIGO syntaxes also allows easy comparison and transition between the different syntaxes, something that can be useful for developers working in all LIGO syntaxes, such as ourselves.

For each contract we’ve also built a basic DAPP, allowing the developer/user to see how the different LIGO/Michelson types are addressed by taquito/JavaScript.

The Calculator DAPP’s UI

The different DAPPs are then integrated into a website that does the wallet connection and allows the user to choose between the different contract examples.

All contracts are migrated and tested using Truffle boxes, which allows the exploring developer to see how that side of the development is done, and there are scripts for running in both sandbox mode and testnet (currently edo2net).

This project is meant to be used by the Tezos developer community, and to answer all of our more “basic” questions regarding writing smart-contracts. We will be very happy to hear your ideas of what contracts to add and what you would like to see from this project. This is all open source so if you have time to contribute to the coding effort, we will greatly appreciate it.

Check out the project here edu.tezos.co.il We will be adding more examples every few weeks so make sure to bookmark the page.

For any suggestions, ideas, and contributions, visit the project’s repository

You can contact us also at our Telegram channel: https://t.me/tezosisrael

--

--