e2m

Converts solidity file to binary move code. You can convert from abi + bin files or a sol file

Feature list

! IMPORTANT
To convert from a sol file, solc must be installed on the computer and accessible from the terminal using the short command solc.
To publish, you need the installed aptos utility

Install solc

How to install solc, see the documentation

Checking solc

The solc version must be at least 0.8.15

solc --version

! IMPORTANT
If this command is not available for execution from the terminal, e2m will not work.

Install aptos

How to install aptos, see the documentation

Checking aptos

The aptos version must be at least 0.3.3

aptos --version

Download e2m

Download link for the latest version of e2m
Unpack the archive and place the executable file in a place convenient for you. For convenience, create an alias e2m in the system for this file.

! IMPORTANT In all examples, e2m will be called via an alias

See help:

e2m --help

Input parameters

  • <PATH> Path to the file. Specify the path to sol file or abi | bin
  • -o, --output Where to save the converted Move binary file
  • --module The name of the move module. If not specified, the name will be taken from the abi path
  • -p, --profile Profile name or address. The address must start with "0x". [default: default]
  • -d, --deploy Deploying the module in aptos node
  • -a, --args Parameters for initialization
  • -i, --interface_package Generate an interface project
  • --native_input Input params of native type
  • --native_output Output value of native type
  • --u128_io Use u128 instead of u256

Example

! IMPORTANT

Before running the examples, you will need to create a private key. It will be used both for the module address and for publishing on the node.

Default profile:

aptos init

Paste the received address into the file samples/sc_users/Move.toml
sc = "_" replace the _ character with the received address

Demo profile:

aptos init --profile demo

See more: aptos init

Module transformation and publication

This command we will make

  • Converting a ./samples/users.sol file to "mv"
  • Generate an interface to use in source. The ./i_users/ folder will appear in the current directory
  • Module will support "move" types
  • We will publish the generated module from the "default" profile
e2m ./samples/users.sol \
   -o ./i_users \
   -a self \
   --native_input \
   --native_output \
   -i \
   -d

Publishing a script

Publishing a script for interacting with the module

Important don't forget to replace the address

aptos move publish \
  --package-dir ./samples/sc_users \
  --max-gas 1000

Calling the module constructor.

Calling the module constructor to assign the current account as the owner

aptos move run \
   --function-id default::ScUser::constructor \
   --max-gas 1000

Adding a "demo" account

aptos move run \
   --function-id default::ScUser::create_user \
   --max-gas 1000 \
   --profile demo

ID verification

account "default": id = 1

aptos move run \
  --function-id default::ScUser::is_id \
  --args u128:1 \ 
  --max-gas 1000

account "demo": id = 2

aptos move run \
  --function-id default::ScUser::is_id \
  --args u128:2 \
  --max-gas 1000 \
  --profile demo

Checking whether this account is the owner:

aptos move run \
   --function-id default::ScUser::is_owner \
   --max-gas 1000

An error will occur when checking from another account

aptos move run \
   --function-id default::ScUser::is_owner \
   --max-gas 1000 \
   --profile demo

Checking the balance

account "default": 10000000000000000000000000000

aptos move run \
  --function-id default::ScUser::check_balance \
  --args u128:10000000000000000000000000000 \
  --max-gas 1000

account "demo": 0

aptos move run \
  --function-id default::ScUser::is_empty_balance \
  --max-gas 1000 \
  --profile demo

Transfer

Sending 200 coins from "default" to "demo"

aptos move run \
  --function-id default::ScUser::transfer \
  --args address:demo u128:200 \
  --max-gas 1000

Checking the transfer

Account default

aptos move run \
  --function-id default::ScUser::check_balance \
  --args u128:9999999999999999999999999800 \
  --max-gas 1000

Account demo

aptos move run \
  --function-id default::ScUser::check_balance \
  --args u128:200 \
  --max-gas 1000 \
  --profile demo