> For the complete documentation index, see [llms.txt](https://docs.endless.link/endless/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.endless.link/endless/devbuild/build/tutorials/your-first-move-module.md).

# Your First Move Module

## Your First Move Module <a href="#your-first-move-module" id="your-first-move-module"></a>

This tutorial details how to compile, test, publish and interact with Move modules on the Endless blockchain. The steps in summary are:

1. Install the precompiled binary for the Endless CLI.
2. Create an account on the Endless blockchain and fund it.
3. Compile and test a Move module.
4. Publish a Move module to the Endless blockchain.
5. Interact with a Move module.

## Step 1: Install the CLI <a href="#step-1-install-the-cli" id="step-1-install-the-cli"></a>

Install the precompiled binary for the Endlesss CLI.

***

## Step 2: Create an account and fund it <a href="#step-2-create-an-account-and-fund-it" id="step-2-create-an-account-and-fund-it"></a>

After installing the CLI binary, create and fund an account on the Endless blockchain.

Start a new terminal and run the following command to initialize a new local account:

```
endless init
```

You will see output asking to choose a network:

```
Choose network from [devnet, testnet, mainnet, local, custom | defaults to devnet]
```

Press **return** to accept the default devnet network or specify the network of your choosing:

```
No network given, using devnet...
```

See and respond to the prompt for your private key by accepting the default to create a new or by entering an existing key:

```
Enter your private key as a hex literal (0x...) [Current: None | No input: Generate new key (or keep one if present)]
```

Assuming you elected to create a new, you will see:

```
No key given, generating key...
Account a345dbfb0c94416589721360f207dcc92ecfe4f06d8ddc1c286f569d59721e5a doesn't exist, creating it and funding it with 100000000 Veins
Account a345dbfb0c94416589721360f207dcc92ecfe4f06d8ddc1c286f569d59721e5a funded successfully

---
Endless CLI is now set up for account a345dbfb0c94416589721360f207dcc92ecfe4f06d8ddc1c286f569d59721e5a as profile default!  Run `endless --help` for more information about commands
{
  "Result": "Success"
}
```

The account address in the above output `a345dbfb0c94416589721360f207dcc92ecfe4f06d8ddc1c286f569d59721e5a` is your new account and is aliased as the profile `default`. This account address will be different for you as it is generated randomly. From now on, either `default` or `0xa345dbfb0c94416589721360f207dcc92ecfe4f06d8ddc1c286f569d59721e5a` are used interchangeably in this document. Of course, substitute your own address as needed.

Now fund this account by running this command:

```
endless account fund-with-move --account default
```

You will see output resembling:

```
Do you want to submit a transaction for a range of [144900 - 217300] Veins at a gas unit price of 100 Veins? [yes/no] >
```

input `yes` to send fund transaction, and console output:

```
tx version: ...
Added fund to account 0xa345dbfb0c94416589721360f207dcc92ecfe4f06d8ddc1c286f569d59721e5a
```

***

## Step 3: Compile and test the module <a href="#step-3-compile-and-test-the-module" id="step-3-compile-and-test-the-module"></a>

Several example Move modules are available in the [move-examples](https://github.com/endless-labs/endless-move-framework/tree/main/move-examples) directory for your use. Open a terminal and change directories into the [`hello_blockchain`](https://github.com/endless-labs/endless-move-framework/tree/main/move-examples/hello_blockchain) directory:

Run the below command to compile the `hello_blockchain` module:

```
endless move compile --named-addresses hello_blockchain=default
```

You will see output resembling:

```
{
  "Result": [
    "a345dbfb0c94416589721360f207dcc92ecfe4f06d8ddc1c286f569d59721e5a::message"
  ]
}
```

The `compile` command must contain `--named-addresses` as above because the [`Move.toml`](https://github.com/endless-labs/endless-move-framework/blob/main/move-examples/hello_blockchain/Move.toml) file leaves this as undefined (see below).

To test the module run:

```
endless move test --named-addresses hello_blockchain=default
```

And receive output like:

```
INCLUDING DEPENDENCY EndlessFramework
INCLUDING DEPENDENCY EndlessStdlib
INCLUDING DEPENDENCY MoveStdlib
BUILDING Examples
Running Move unit tests
[ PASS    ] 0x1a42874787568af30c785622899a27dacce066d671fa487e7fb958d6d0c85077::message::sender_can_set_message
[ PASS    ] 0x1a42874787568af30c785622899a27dacce066d671fa487e7fb958d6d0c85077::message_tests::sender_can_set_message
Test result: OK. Total tests: 2; passed: 2; failed: 0
{
  "Result": "Success"
}
```

To prepare the module for the account created in the previous step, we specify that the named address `hello_blockchain` is set to our account address, using the `default` profile alias.

```
[addresses]
hello_blockchain = "_"
```

***

## Step 4: Publish the Move module <a href="#step-4-publish-the-move-module" id="step-4-publish-the-move-module"></a>

After the code is compiled and tested, we can publish the module to the account created for this tutorial with the command:

```
endless move publish --named-addresses hello_blockchain=default
```

You will see the output similar to:

```
package size 1631 bytes
{
  "Result": {
    "transaction_hash": "0x45d682997beab297a9a39237c588d31da1cd2c950c5ab498e37984e367b0fc25",
    "gas_used": 13,
    "gas_unit_price": 1,
    "pending": null,
    "sender": "a345dbfb0c94416589721360f207dcc92ecfe4f06d8ddc1c286f569d59721e5a",
    "sequence_number": 8,
    "success": true,
    "timestamp_us": 1661320216343795,
    "version": 3977,
    "vm_status": "Executed successfully"
  }
}
```

At this point, the module is now stored on the account in the Endless blockchain.

***

## Step 5: Interact with the Move module <a href="#step-5-interact-with-the-move-module" id="step-5-interact-with-the-move-module"></a>

Move modules expose access points, known as *entry functions*. These entry functions can be called via transactions. The Endless CLI allows for seamless access to these entry functions. The example Move module `hello_blockchain` exposes a `set_message` entry function that takes in a `string`. This can be called via the CLI:

```
endless move run \
  --function-id 'default::message::set_message' \
  --args 'string:hello, blockchain'
```

Upon success, the CLI will print out the following:

```
{
  "Result": {
    "transaction_hash": "0x1fe06f61c49777086497b199f3d4acbee9ea58976d37fdc06d1ea48a511a9e82",
    "gas_used": 1,
    "gas_unit_price": 1,
    "pending": null,
    "sender": "a345dbfb0c94416589721360f207dcc92ecfe4f06d8ddc1c286f569d59721e5a",
    "sequence_number": 1,
    "success": true,
    "timestamp_us": 1661320878825763,
    "version": 5936,
    "vm_status": "Executed successfully"
  }
}
```

The `set_message` function modifies the `hello_blockchain` `MessageHolder` resource. A resource is a data structure that is stored in global storage. The resource can be read by querying the following REST API:

```

https://rpc-test.endless.link/v1/accounts/a345dbfb0c94416589721360f207dcc92ecfe4f06d8ddc1c286f569d59721e5a/resource/0xa345dbfb0c94416589721360f207dcc92ecfe4f06d8ddc1c286f569d59721e5a::message::MessageHolder
```

After the first execution, this should contain:

```
{
  "type": "0xa345dbfb0c94416589721360f207dcc92ecfe4f06d8ddc1c286f569d59721e5a::message::MessageHolder",
  "data": {
    "message": "hello, blockchain"
  }
}
```

Notice that the `message` field contains `hello, blockchain`.

Each succesful call to `set_message` after the first call results in the `MessageChange` event being emitted. `MessageChange` is a [Module Event](https://docs.endless.link/endless/devbuild/start/learn-about-endless/events#module-events).

{% hint style="info" %}
Other accounts can reuse the published module by calling the exact same function as in this example. It is left as an exercise to the reader.
{% endhint %}

## Supporting documentation <a href="#supporting-documentation" id="supporting-documentation"></a>

* [Account basics](/endless/devbuild/technical-documentation/endless-account.md)
* [TypeScript SDK](https://github.com/endless-labs/endless-ts-sdk)
* [Golang SDK](https://github.com/endless-labs/endless-go-sdk)
* [Rust SDK](https://github.com/endless-labs/endless-rust-sdk)
* [REST API specification of Testnet](https://rpc-test.endless.link/v1/spec#/)
