Aptos Blockchain Interaction Guide

Aptos blockchain uses the Move virtual machine to perform operations. While many blockchains implement a set of their own operations, Aptos delegates all operations to Move, including: creating an account, transferring funds, and publishing Move modules. To support these operations, a blockchain built on Move must provide a framework (similar to an operating system for a computer or a minimal set of functions) for interacting with the blockchain. In this section, we discuss these functions, exposed through script<###code> features of the Aptos Framework.

This tutorial (combined with the Move module tutorial) will reveal the minimum amount of information you need to start building rich applications based on the Aptos blockchain. Note: The Aptos Framework is under active development, so this document may not be up to date. The most recent version of the framework can be found in the source code here.

The main features provided to users within the Aptos Framework include:

  • Sending and receiving network coin Coin<AptosCoin>.
  • Creating a new account
  • Publishing a new Move module

Note: this document assumes that readers are already familiar with sending transactions as described in the Your First Transaction guide.

Sending and Receiving Network Coin Coin<AptosCoin>

Coin<AptosCoin> is needed to pay the gas fee for sending and executing transactions.

The payload to send a command to the blockchain to execute the transfer is:

  "type": "entry_function_payload",
  "function": "0x1::Coin::transfer",
  "type_arguments": ["0x1::aptos_coin::AptosCoin"],
  "arguments": [
Enter fullscreen mode Exit fullscreen mode

This instructs the virtual machine to execute script 0x1::Coin::transfer with an argument of type 0x1::aptos_coin::AptosCoin. The type is needed here because Coin is our standard module, which can be used to create many Coin types. For an example of creating a custom Coin, see the "Your First Coin" guide. The first argument is the recipient address, 0x737b36c96926043794ed3a0b3eaaceaf, and the second argument is the transfer amount, 1000. The sender address is the address of the account which sent the transaction, requesting this script.

Creating a new account

The payload for giving the blockchain the command to create a new account is as follows:

  "type": "entry_function_payload",
  "function": "0x1::AptosAccount::create_account",
  "type_arguments": [],
  "arguments": [
Enter fullscreen mode Exit fullscreen mode

This instructs the Move virtual machine to execute script 0x1::AptosAccount::create_account. The first argument is the address of the account to be created, and the second is the pre-image of the authentication key (which is mentioned under Accounts). For single-signature authentication, it is a public key concatenated with the byte 0 (or pubkey_A | 0x00). This is necessary to prevent an address from being assigned to an account. Executing this instruction verifies that the last 16 bytes of the authentication key match the 16-byte account address. We're actively working on improving this API to accept a 32-byte account address, which will eliminate the fear of account attribution or manipulation.

Publishing the new Move module.

A useful load to pass a command to the blockchain to publish a new module is:

"type": "module_bundle_payload",
"modules": [
    {"bytecode": "0x..."},
Enter fullscreen mode Exit fullscreen mode.

This instructs the virtual machine to publish the module bytecode under the sender account. See your first Move module for a full tutorial.

It is important to note that the Move bytecode must specify the same address as the sender account, otherwise the transaction will be rejected. For example, if the account address is 0xe110, the Move module must be updated as such module 0xe110::Message, module 0xbar::Message will be rejected. Alternatively, you can use an alias address, such as module HelloBlockchain::Message, but the alias HelloBlockchain will need to be updated to 0xe110 in the Move.toml file. We are working with the Move command and plan to include a compiler in our REST interface to mitigate this issue.

Оцените статью
Добавить комментарий