A Newbie’s Paradise: How to Visually Program Smart Contracts with VisualTez
The VisualTez visual programming service appeared on Tezos as early as May. It leaves it to the developer to select the blocks they need with the mouse, combine them and set arguments, while the service does the rest.
We have built a simple calculator contract in VisualTez and tested it right away. In this post, we share our impressions of the visual programming of smart contracts in Tezos and talk about the features of this tool.
Who Needs Visual Programming
First, it is suitable for creating simple scripts without learning the nuts and bolts of the platform. For example, you can use the Automate app to program your smartphone to turn off WiFi when it is not at home or office according to GPS readings. To do this, you don’t need to know Java and corresponding functions to work with WiFi and GPS.
Secondly, visual programming allows the narrow specialists to concentrate on solving a particular creative problem as exemplified by Blueprints in Unreal Engine for working with graphic shaders, AudioMulch for writing music, or Houdini for 3D animation.
Third, programming with blocks and arrows is useful for teaching newcomers who are not yet used to operating with abstractions or are confused about the syntax and semantics of the language.
In general, visual programming is suitable for people who know what to do but have not yet fully mastered the programming language or do not have time to learn it. It’s also useful for prototyping and experimentation when it’s faster to put together a few blocks with a mouse than to write twenty lines of code.
How to Work with VisualTez
The main screen has two main links: one to the editor (IDE), and the other to the documentation. Still, the documentation only explains how to work with blocks, and compile and test contracts in VisualTez. If you happen to not know how big_map differs from record and what a Storage is, we recommend that you read our development course or SmartPy documentation.
VisualTez saves workspace progress and allows you to share permanent links to your contract. This way the workspace content won’t disappear if you accidentally close your browser or reload your tab.
On the left-hand side, there is a menu with blocks:
- Main Blocks, the containers that are responsible for compiling smart contracts, values, and types;
- Data Values;
- Operations by Type, such as get string length, remove key from map, and others;
- Operations with Variables, i.e. declaration, assignment, access;
- Logic operations;
- Arithmetics/Math functions, like ABS and shift operators;
- Transfer and tez delegation, as well as third-party contract call and deployment;
- Access to on-chain data (Block/Tx Properties), i.e. functions like Get Sender;
- Cryptographic functions (Cryptography), e.g. signature verification;
- Advanced expressions for packing and unpacking data;
- Lambda calculations;
- On-chain views;
- Functions for testing.
On the right-hand side, you have tools for working with contracts: compiling and testing, FA1.2 and FA2 templates, generating a permalink to a workspace with your contract, importing and exporting contracts in .xml format, and more.
Contracts are compiled in Michelson, JSON, or SmartPy.
A Simple Calculator Contract Is All We Need
Here we describe the whole process of creating a contract with bumps and errors to show where the problems were and how intuitive this way of programming is.
Our contract will have two entrypoints: addition and subtraction. When the entrypoint is called, the user passes an argument of type int, which the contract adds or subtracts from the value in the storage.
First, we add the Contract Compilation block from Main Blocks: therein, we set the storage type and its initial state.
Change the storage type from Unit to int and set the original value to 0. To do this, in the menu on the left choose int types and drag the blocks to the appropriate places.
The first error we did was to try to drag an int block from the Types menu, while it had to be from Values as we are setting up a value, not just a type.
We add two entry points, name them and set the type of the incoming parameter to Int. They need to implement a function like “storage = storage + parameter”.
The second error was about a long search for a block in Values and Types to assign a new value to the storage. It turned out to be simple: in the menu Variables, we choose a block called Assign value and add storage and mathematical operation, in which we add two variables Storage and Parameter.
In the same way, we fill the subtraction function, only with a minus in the function. By the way, VisualTez allows one to copy blocks with whatever they contain, so we just had to copy the block and assign the new value of Storage.
Now we can compile a smart contract. In SmartPy, it looks like this:
VisualTez has no Dry Run, i.e. a test run of a contract with a given input parameter. So we write a test: we deploy the contract, call the entry points, and give them arguments. In the first test, we add 10, in the second, we subtract 15, in the third, we try to subtract the line “kek” to get an error.
When testing, we first got an unexpected virtual machine error, because we forgot about an important thing: Michelson cannot into space, sorry, strings, and they need to be converted to byte format. So we replaced the string “kek” with a natural number 0, and our contract successfully passed the tests.
But Seriously. Try VisualTez
Overall, we are happy with the results and the experience with VisualTez. The only thing that is a little confusing is that the backgrounds in the workspace and the block selection menu are nearly identical. And so, for example, when you click Main Blocks, you might be completely sure for a short while that you’ve added four available blocks to the screen at once.
Building a contract in VisualTez was much easier and faster than we expected. If you’ve tried developing in LIGO or SmartPy before, but gave up because of the complexity, try writing something in VisualTez. You’ll enjoy it.
If you’re an experienced developer, give it a try too. VisualTez might suit you as a tool for prototyping or experimentation.
Subscribe and never miss updates from the world of Tezos: