Create the Move Smart Contract

For this guide we'll create an automation contract that will increment a default value with each automated transaction once the automaton task gets started. We can then use the view function and/or SupraScan to see the updated value, old value, timestamp, and total increments.

Best Practice for Gas Optimization: If you're using AutoFi's trade contracts (limit orders, DCA, etc.) then:

  • Initialize storage in init_module (runs once at deployment)

  • Do NOT initialize storage inside your automation task function (runs repeatedly)

  • This pattern minimises gas by avoiding storage creation and you can save automation the fee.

  • Storage creation is required only once hence Performing it in the init module or a dedicated setup function.

  • Handling storage creation within the automation function would require a high gas limit, which is unnecessary for a one-time operation. Hence, this approach is more efficient.

Example:

// Storage created once 
fun init_module(account: &signer) { move_to(account, Counter { value: 0, ... }); }

// Task only operates on existing storage 
public entry fun auto_increment(account: &signer) acquires Counter { let counter = borrow_global_mut(account_addr); counter.value = counter.value + 1; }

Initialize your move package

1

Create a new Move package

execute me!
supra move tool init --package-dir /supra/move_workspace/autofi --name autofi

This will create your project directory automatically, including a Move.toml file. This is a manifest file that contains important metadata about your package. This includes the package name, version, dependencies, named addresses, and more.

The SupraFramework dependency is automatically populated. This framework includes core components that you will interact with during your time on Supra. The framework package includes clearly defined documentation within the /doc directory for you to review alongside the Move code within the /sources directory. You can view this package here.

move.toml
[package]
name = "autofi"
version = "1.0.0"
authors = []

[addresses]

[dev-addresses]

[dependencies.SupraFramework]
git = "https://github.com/Entropy-Foundation/aptos-core.git"
rev = "dev"
subdir = "aptos-move/framework/supra-framework"

[dev-dependencies]
2

Update the named addresses

Open the move.toml file with your code editor. You can find these files on your host machine in the /supra/move_workspace/autofi directory.

For now, add the below named address to your Move.toml file and set the value to your address.

You can view the address of your profiles by executing: supra profile -l

[addresses]
exampleAddress ="YOUR-ADDRESS-HERE"

Named addresses allow identifiers such as @exampleAddress to be used throughout your package, rather than hard coding an address value. When compiled into bytecode, any occurrence of the identifier such as @exampleAddress will be replaced with the value set within the move.toml file.

Write & Publish Your Module

1

Create a Module Smart Contract (Module)

2

Publish Your Move Package on Supra Network.

3

Use SupraScan to confirm it was deployed successfully.

Last updated