AptosVM <> MEVM
In this guide you will learn how to send transactions between AptosVM and MEVM.
Overview
Welcome to the tutorial for using Movement Labs' blockchain and the Move language! In this tutorial, we will cover two parts:
Part 1: Signing Multi-Party Transactions with Multi-Signature Accounts - including an MEVM multisig Safe Wallet!
Part 2: Calling an EVM Smart Contract from an AptosVM Wallet
Requirements
Node.js
npm
Setup
Clone our demo repository to access the necessary files:
Access the app directory:
Install all dependencies:
Open your favorite IDE. We recommend using VSCode:
You will find an .env
file in the app directory. Most variables are already filled in, but pay attention to MOVE_PRIVATE_KEY
and ETHEREUM_PRIVATE_KEY
. Make sure you use private keys for wallets that have been funded. You can use our Faucet to fund them.
Note: The following variables are needed for the demo:
MOVE_MULTISIG_OTHER_OWNER_ADDR
MOVE_FRAMEWORK
EVM_PRECOMPILE_CONTRACT
After setting your private keys, let's take a look at our setup. At the top, we import our dependencies:
ethers
: Ethereum wallet and utilities@safe-global/protocol-kit
: Toolkit for interacting with the Safe protocolaptos
: Library for interacting with the Aptos protocoldotenv
: Module for loading environment variables from a.env
file intoprocess.env
Part 1: MEVM to AptosVM
Head to mevm-to-aptosvm.js
. You will find several functions. Feel free to explore them and understand what they do.
deploySafe()
: Deploys a new, MEVM Safe contractsetupMoveMultisigAccount(safeAddress)
: Sets up a new Move multisig accountvote(safeAddress, multiAccount)
: Votes on a a Move proposal from a Safe contractcheckSafeContractVoted(safeAddress, multiAccount)
: Checks if a Safe contract has been voted onsubmitTx(rawTxn)
: Submits a transactionzeroPad(multiAccount)
: Pads with zeroes if the multiAccount address has a different size then the Move address type.
Now, all you have to do is run:
Essentially, the following is what the script will perform:
Creates a Gnosis Safe smart contract using the EVM wallet.
Creates a multisig account using the Move wallet, and sets the Gnosis Safe contract created in step 1 as one of the owners.
Creates a multisig transaction (the content can be arbitrary, but for this demo we are adding an owner to the multisig account) and votes using the Move wallet.
Creates a transaction using the EVM wallet to vote for the transaction created in the previous step in the Move multisig account.
Proposes and confirms the transaction created by the EVM wallet to the deployed Safe service.
Executes the transaction the confirmed transaction.
Checks whether the EVM multisig account has voted successfully.
As you can see, we are interfacing between AptosVM and MEVM when we finally sign a Move transaction from the EVM multisig. To do so, we have to pay attention to the vote()
function:
To interact between AptosVM and MEVM, pay attention to the vote()
function, where we encode a Move transaction and pass it to the callMove()
precompile function, which serves as the entry point for calling Move functions from MEVM.
Part 2: AptosVM to MEVM
Now, head to aptosvm-to-mevm.js.
You will find a tighter script:
deployNumberRegistry()
: Deploys a new SolidityNumberRegistry
smart contractsubmitTx(rawTxn)
: Submits an AptosVM transactiongetNonce(addr)
: gets the EVM nonce of an AptosVM Account.setNumber(contract)
: Calls the setNumber function present in theNumberRegistry
smart contract
Now you can run the script:
This is what the script will perform:
Creates a
NumberRegistry.sol
smart contract using the EVM wallet.Calls the
setNumber()
function of the NumberRegistry contract using the Move wallet.Checks whether the number was set successfully.
Here we should pay special attention to the setNumber()
function:
Here we are encoding an EVM function and passing it to the 0x1::evm::send_move_tx_to_evm
function present in our evm
framework.
In the setNumber()
function, we encode an EVM function and pass it to the 0x1::evm::send_move_tx_to_evm
function in our EVM framework.
Conclusion
That concludes our tutorial! We've covered signing multi-party transactions with multi-signature accounts from an EVM multisig and calling EVM smart contracts from an AptosVM wallet.
Feel free to reach out to us on Discord if you have any issues, questions or feedback. We would love to hear from you!
Last updated