How to start with the MultiversX blockchain development

github twitter github

Lately, I got a couple of questions about starting coding in the MultiversX ecosystem. I want to share my thoughts about it.

There is a lot about MultiversX nowadays on my blog, but I have a time where I learn a lot of the tech behind it, so also I would like to share as much as I can. Ok, let's see how it started for me.

How I started

I searched for some new layer one blockchain with a new approach. What I was interested in most back then was mostly the dev architecture and coding possibilities, not the economic fundamentals and investing opportunities, which are also good.

My main goal was to check a couple of documentation sites and choose the most simple to start. I read a couple of them, and the MultiversX (MultiversX) docs were the most appealing to me. There weren't much of docs back then, some of the docs were not updated, but still, it was enough to decide that this looked good, and starting with it should be simple.

I haven't had much experience using Rust, and I still don't have. But my goal was to choose the blockchain where smart contracts are written in Rust. Primarily because of my willingness to learn it in that context. Of course, I did not start by writing smart contracts. I started from JavaScript SDK research because this was familiar to me.

I always say that the best way of learning is to build something, and even better is to make something that other people will use. It motivates the most.

How to start coding in the MultiversX ecosystem

My advice would be to focus on some problems you want to solve. It doesn't matter if someone has already solved them. Just figure out something and focus on it.

My idea was to prepare tools for running the NFT collections on MultiversX. It is how Elven Tools was born, but it can be anything.

Please remember that all of the tutorials, articles, and documentation can't be maintained in real-time. It is time-consuming. So there will always be outdated stuff on the Internet.

Ok, let's finally jump into the topic...

I would say that the first place to start would be the official docs. From my experience, it doesn't matter how good they are. It will always be a little harder to understand them initially. It is normal. There is a lot of stuff there because it should be complete, and it is easy to get lost in that. You will find a couple of my simple guides in the following paragraphs.

If you want to be a coder in the MultiversX ecosystem, you must decide what you want to code. Will it be a smart contract or a dapp which interacts with the protocol or a smart contract? Let's split that into two sections to get the bigger picture. Let's start with learning tips when it comes to smart contracts.

How to start coding MultiversX smart contracts?

The best will be if you are already a Rust developer. But from my experience, it isn't required at all to start. Of course, it is always good to have someone to provide some audits and improvements, especially for production-ready solutions. But if you want to start creating, it isn't required. So start without thinking about it. Just create. Let's see how.

What you would need is:

  • Rust environment configuration. mxpy tool + VSCode extension.
  • multiversx-sc - the framework of the smart contracts.
  • Examples of smart contracts to start. I will also list a couple of them.
  • Proper docs at hand. I will list them here but always search for more.

To work with the MultiversX smart contracts, you need the Rust environment. You can do this manually and configure it all by hand, but there is also an option to use the VSCode plugin. You will find it here: MultiversX VSCode.

You will also need the core tool, mxpy. The tool is written in Python, and it is the primary CLI tool for everything MultiversX-related. You can also use it as a dependency in your Python project. It is also the backbone of the VSCode plugin. You can install and configure it on Linux and macOS with a simple command: Installing mxpy. Check what it can do by running commands with the --help flag for every subcommand, or you can check all of it here: CLI overview. Btw. I love that tool!

Ok, so you have the mxpy and the VSCode extension. Now you can start writing smart contracts. But before that, let's take a look at the core MultiversX Rust library, which is multiversx Rust SDK. You will always return to this repo because this is the main framework. Remember that not all functions are documented yet. But don't worry, the code is clean, and it is straightforward to read even if you don't code in Rust daily.

You would need to have some documentation to start with it. But before that, let's get some smart contract examples.

The best place to start reviewing the code would be excellent Web IDE: MultiversX Play. You will find there ready-to-use smart contracts. You can study the code, compile it and even deploy it to the devnet. But remember, this is mostly for demonstration purposes, quick tests, and learning.

There are other places where you can review the code of smart contracts. If you are searching for something straightforward to start, I recommend my simple, smart contract for learning purposes: multiversx-simple-sc. There are also articles and videos about it. You will find the links in the readme.md file in the repo. The code is up to date, but be careful with videos, compare them with the code and docs. The smart contract is so straightforward that it shouldn't be a problem to figure out stuff.

If you need something more complicated and real-live use cases, you can go through the MultiversX GitHub. You can start from here:

Also, please check the Elven Tools smart contract, which is also open source: elven-nft-minter-sc.

You can open each repository in VSCode with the MultiversX IDE extension installed, or you can also use mxpy as the only CLI tool to deploy and interact with the smart contract. Check examples in the readme.md here: multiversx-simple-sc but also in the docs linked above.

Ok, so you have the mxpy. You have a lot of smart contracts code. Now we can check the most valuable sections in the MultiversX documentation.

I will try to point you to the essential parts in the official documentation. Let's start from Smart contract annotations. You will find what code structures are required. You will learn to use the mandatory 'init' function or the difference between the 'view' and 'endpoint' annotation. And, of course, how to use the storage on smart contract. It all is the backbone of every smart contract.

Next, there is also a section regarding Smart Contract API Functions. Here you will learn about the most used API functions from MultiversX Rust SDK. Remember that the list is incomplete, so always search the code. You will know what functions you can use in your smart contract.

There is also an introductory section about serialization: The MultiversX Serialization Format. You will learn how to use many different data structures and how they should be used across the protocol.

The last here, but not least, is the Developers Best Practices. You'll find a lot of information about the most common mistakes and how the smart contract should be structured, a valuable source of knowledge for beginners in the ecosystem.

Ok, let's stop here. This article is not about diving into technology. It is more about pointing out the tools and places where the developer can start. There is a lot more helpful knowledge in the docs. You'll find a lot about the testing, debugging, ESDT/NFT/SFT tokens, and of course, a lot of information about setting up the testnet locally, managing wallets, and a lot more.

Smart contracts are just one piece of the puzzle. Every complete project would need to provide frontends or other tools to interact with the smart contract. Let's see what tools we can use to achieve that in the MultiversX ecosystem.

How to code the dApps and interact with MultiversX smart contracts?

You will use the JS SDK. The tool is written using Typescript, and it can be used in the browser (with some adjustments) and mainly in the NodeJS backends.

What you would need to start with JS SDK is:

  • Understanding what it is.
  • How to use it with the most popular frontend frameworks.
  • Code examples.
  • What are the frontend tools built as a layer on top of JS SDK.
  • Docs?

Let's look at what the JS SDK can do for you. In short, it will help with everything related to interaction with the protocol and smart contracts. The most used functionality would be creating, signing, and sending transactions, querying smart contracts, handling accounts, addresses, etc.

The best place to start with it is the JS SDK readme.md file. You will find here the most important examples. You can also look at the test cases in separate 'spec' files. There will be more examples later in the article. For now, let's take a closer look at using the library in the most popular frontend frameworks.

Because JS SDK uses some of the native NodeJS modules, it is required to use polyfills when using React apps, such as the NextJS framework. But it will be the same for the Vue ecosystem.

For example, when using the Webpack with React and NextJS, you must add a couple of polyfills to the next.config.js. For example:

/** @type {import('next').NextConfig} */

const nextConfig = {
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
    config.resolve.fallback = {
      fs: false,
      buffer: require.resolve('buffer'),
      crypto: require.resolve('crypto-browserify'),
      path: require.resolve('path-browserify'),
      stream: require.resolve('stream-browserify'),
      process: require.resolve('process/browser'),
    };
    return config;
  },
  reactStrictMode: true,
};

module.exports = nextConfig;

You'll find all possible polyfills here: Webpack resolve fallback. As for other tools, the process is similar. You would need to figure out how to add these polyfills to your setup.

The other option is to use it in vanilla javascript in the browser. It is also possible, but you need to use the version generated using the browserify tool.

Ok, let's see some examples of the code. As I wrote previously, the spec files with tests in the JS SDK repo are good resources here, but there is also an excellent repository with example snippets. You will find it here: sdk-js-snippets. You will find a lot of example code there. Very useful. You could also check the Elven Tools CLI source code. The JS SDK library is used there in almost all places.

JS SDK is the primary Typescript/Javascript tool, but there is also a tool built upon it that will help bootstrap the frontend app based on React. It is sdk-dapp. The library provides common React utilities and components to help with authentication, accounts handling, and transactions. So it is a tool that will save you a couple of hours or even days of work. Of course, using only the JS SDK for all of that is also possible.

I work on frontend tooling for Elven Tools. It will be an open-source NextJS template that could also be used for different projects, with some modifications. I'll update this article when ready.

Ok, so where are the docs for JS SDK?

There are no official docs on JS SDK yet. Or, to be more precise, the code is self-documenting. I am sure that the docs will be there in the future, but for now, there are many examples and test cases in the codebase, and it is pretty simple to understand. The codebase of JS SDK is very clean, with comments, and I think everyone who knows how to read JavaScript will find everything very quickly.

If you would like to read more about the JS SDK and examples, you can check the Building NFT related CLI tool with MultiversX's JavaScript SDK article, where I wrote a couple of words about JS SDK and how to use it in most typical situations.

Summary

I think I wrote about the most important things when you would like to start coding in the MultiversX ecosystem. It is crucial to add a couple of more links that are very helpful in this path. Please let me know what else could be added here.

If you have any suggestions or questions, please get in touch with me on Twitter. Also, please check the Elven Tools project and my GitHub, where you will find a lot of open-source tools.