Welcome to the world of Move, a smart contract language designed for the Web3 era! In this tutorial, we'll help you set up your environment, create your first Move application, and test it locally. So let's dive in and learn how to write smart contracts using Move.

Prerequisites

  1. Install Visual Studio Code (version 1.43.0 and above) from here.
  2. Install Move-Analyzer IDE from this link.

Setting up the Project Environment

  1. Create a new directory for your project and open it in Visual Studio Code.
  2. Create the following directory structure within your project directory:
modules/   - directory for our modules
scripts/   - directory for transaction scripts
out/       - this directory will hold compiled sources
  1. Create a file named .mvconfig.json in the root of your project directory to configure your working environment. Here's a sample configuration for the libra network:
{
    "network": "libra",
    "sender": "0x1"
}

Or you can use dfinance as network:

{
    "network": "dfinance",
    "sender": "0x1"
}

Creating Your First Move Application

Now that your environment is set up, let's create a simple Move application that implements a gimme_five() function.

Create the Module

  1. Create a new file called hello_world.move inside the modules/ directory of your project:
// modules/hello_world.move
address 0x1 {
module HelloWorld {
    public fun gimme_five(): u8 {
        5
    }
}
}

Write the Script

  1. Create a new file called run_hello.move inside the scripts/ directory of your project:

// scripts/run_hello.move
script {
    use 0x1::HelloWorld;
    use 0x1::Debug;

    fun main() {
        let five = HelloWorld::gimme_five();

        Debug::print<u8>(&five);
    }
}