Building on Move – Aptos

As the bull run market approaches, numerous projects are set to launch in the near future, resulting in a surge of ICO/IDO/IGO events. In this article, Icetea Software will share a Move smart contract written in the Move programming language with MoveVM, which enables users to disperse coins (transfer coins to multiple recipients in varying amounts) on the Aptos blockchain.

1. Disperse Coin with Move Smart Contract:

To facilitate the distribution of coins to multiple recipients, we have developed a Move smart contract. This contract leverages the capabilities of the Move programming language and MoveVM to accomplish the task efficiently. Let’s examine the smart contract in detail.

2. Smart Contract Explanation:

The smart contract consists of two main functions for coin dispersion. The purpose behind having two functions is as follows:

  • Disperse to Registered Wallets:

One function enables dispersing coins to wallets that have registered for a specific coin. This feature ensures that only relevant coins are sent to recipients, avoiding the distribution of unwanted or irrelevant coins to their wallets.

  • Disperse to All Wallets:

The second function disperses coins to all wallets, but it verifies whether each recipient has registered for the specific coin. If a wallet has not registered, an error aborts the transaction.

Furthermore, Move programming language differs from other blockchain programming languages, as it solely utilizes a while loop instead of a for loop. Thus, the variable “i” is declared to track the loop’s completion. Additionally, Move employs vectors instead of arrays for data storage. In our smart contract, the parameters consist of two vectors: one containing wallet addresses and the other containing the corresponding number of coins to be distributed.

To access elements within the vector, we utilize the vector::length function, which provides the length of the vector. The syntax of Move is notably similar to Rust, offering familiarity to developers experienced in Rust programming.

Importing libraries in Move is straightforward. In the provided example, the common coin standard library in Aptos is imported using the command “use aptos_framework::coin.” This is akin to using the openzeppelin’s ERC20 library with EVM, providing convenience and functionality

3. Smart Contract Interaction with JavaScript:

To interact with the Move smart contract, we utilize JavaScript. In the “init” function, a wallet account is created using the provided address, private key, and public key. Additionally, the total number of tokens to be dispersed is checked.

If a wallet has not registered for a particular coin, a “register coin” function is invoked by calling the relevant function from the aptos_framework resource in the blockchain.

To call a Move smart contract, a payload must be prepared, specifying the entry function, module name, module address, and arguments. The payload is structured accordingly, including the token name within the type argument, as depicted in the provided example. Finally, the recipients and corresponding amounts are passed as arguments.

Once the payload is prepared, client functions are invoked to submit the transaction to the blockchain, completing the process.

The Move smart contract presented in this article enables efficient and secure dispersion of coins on the Aptos blockchain. By leveraging the features of the Move programming language and MoveVM, developers can streamline the distribution process for ICO/IDO/IGO events in the upcoming bull run market.

Source: Link 1, Link 2, Link 3