How to execute and deploy Move script?

Hi

I am able to run commands from Libra CLI but I am unsure how to execute examples given; what would the file extension and how would they run on Blockchain. Can anyone guide?

4 Likes

Good places to start are:

The file extension is .mvir

You can find many small Move IR examples in the tests. The easiest way to experiment with Move IR is to create a new test in this directory and follow the instructions for runnning the tests.

Just going to note down the steps I took to compile and run a Move script as I go along (note, this is a work in progress).

1. Clone and build the Libra Core

Instructions here: https://developers.libra.org/docs/my-first-transaction#clone-and-build-libra-core

2. Build the compiler

In the folder you installed Libra Core you, use cargo to build the compiler:

cargo build --bin compiler

You can read more about this: https://github.com/libra/libra/blob/master/language/compiler/README.md

3. Run the compiler

Navigate to the folder where the compiler was created:

cd target/debug

See what commands are available using:
./compiler --help

4. Compile a script

We’ll compile one of the available test scripts:

./compiler ../../language/functional_tests/tests/testsuite/examples/script.mvir

which will output:

CompiledProgram: {
Modules: [
],
Script: CompiledScript: {
Main:
	public 0x0.<SELF>.main(): ()
		locals(0): ,
		Ret
Struct Handles: []
Module Handles: [
	0x0.<SELF>,]
Function Handles: [
	0x0.<SELF>.main(): (),]
Type Signatures: []
Function Signatures: [
	(): (),]
Locals Signatures: [
	,]
Strings: [
	<SELF>,
	main,]
ByteArrays: []
Addresses: [
	0x0,]
}

}

Alternatively, you can compile the test script to a specific folder / location, using:

./compiler -o ../../language/functional_tests/tests/testsuite/examples/MYOUTPUTTEDFILE ../../language/functional_tests/tests/testsuite/examples/script.mvir

… Not sure what to do next, can anyone carry this on? :slight_smile:

7 Likes

Hi,

We have faced the same challenges and found work arounds using local environment, and help and discussion with the libra team. We documented our experience and shared our code. Check

4 Likes

Hi,

Move dev here. Right now the easiest way to run a custom move transaction is to write it as a test (.mvir file under libra/language/functional_tests/tests/testsuite/). You can then run the tests using the following commands:

// runs all the tests
cargo test -p functional_tests

// runs only the tests with "xyz" in the name
cargo test -p functional_tests xyz

@Omri has made an excellent tutorial on this and I recommend you check it out.

Note: tests are connected to an in-memory (fake) storage instead of a blockchain. We are also working on tools that will make this process easier so stay tuned.

7 Likes