Deploying Solidity Contracts on M1 using Hardhat and Fractal
This tutorial will walk you through deploying a Solidity smart contract on M1 using Fractal Transpiler and Hardhat.
Our toolkit
What is Hardhat?
Hardhat is a powerful Javascript smart contract development toolchain for Ethereum Virtual Machines.
What is Fractal?
Fractal is Movement Labs' transpiler that allows any developer to deploy any Solidity smart contract on M1 a Move language based Virtual Machine, effectively turning Solidity code into Move code, inheriting all of the security properties natively available to Move smart contracts.
Prerequisites
Before you begin this tutorial, you'll need to:
Step 1: Fund your wallet with MOV tokens
Fund an EVM wallet address with some MOV
tokens using our faucet. Another method to get get MOV
is to bridge from M1 to your EVM wallet using our bridge. To connect to our testnet and check if you have received the MOV
tokens, you can take the following steps:
Add the move-evm network to your EVM-compatible wallet.
Property Value Network Name
move-evm
Network RPC
https://mevm.devnet.m1.movementlabs.xyz
Network ID
0x0150
Network Currency
MOV
Ensure you have switched your Wallet network to the network added above, i.e.,
move-evm
.
Step 2: Setup your Hardhat project
Create your project directory:
And access it:
Initiate your Hardhat project:
Go through the steps and choose your preferences. Here we will be going through the defaults and choosing a javascript project. We named the project hardhat-move-evm.
If you have not accepted the dependency installation, please do so. If you are doing a custom installation, make sure you are using the correct dependencies:
Make sure to also install dotenv:
Open the project in your favorite editor. Here we are using VSCode
Create an .env file
Add your private key to the .env file. You can obtain your private key from your EVM wallet that you funded with MOV
. For example, if you are using MetaMask, you can find your private key under Settings > Advanced > Export Private Key. Make sure to keep your private key safe and never share it with anyone.
On the root folder you will be able to find hardhat.config.js
. This is the configuration file for hardhat. Add M1 network configurations by replacing its contents with the following:
Step 3: Write your Solidity contract
Here we we will be introducing minimal changes to our contracts to make your life easier. There is nothing intrisic here that is specific to M1. You can write your contracts as you would normally do.
Under contracts/
open the file Lock.sol. This is the Smart Contract that you will be deploying to M1. You can replace the contents of this file with your own contract.
You have a state variable unlockTime
and one function, withdraw
to withdraw the funds from the contract.
Now, under scripts
, open the file deploy.js
. This is a simple script that we will use to deploy our contract on M1. You can replace the contents of this file with your own script.
This will deploy the contract available at contracts/Lock.sol. You can tinker with it and change its logic, feel free to try things out!
Step 4: Deploy your Solidity contract
To deploy your contract, run the following command:
After running it, you should see a similar message in your console:
Success! You have successfully deployed your contract using Hardhat. You should now be able to interact with the contract provided by the message above.
Step 5: Interact with your Solidity contract
Now that you have your contract, you can also interact with it using Hardhat. To do so, we will write another script. Under script
, create a new file withdraw.js
and add the following contents:
Make sure to replace <lockAddress>
with the address of your deployed contract. You can find it in the message printed in your console after deploying your contract.
Now, all you have to do is run the following command:
If you are succesful, you should see the following message:
That's it! If you are used to deploying contract to EVM networks, this should feel like being at home. If you are not, we hope this tutorial was helpful and that you are now ready to work on your contract and deploy your own contracts and continue building on M1.
If you would like to learn more about M1 and deploy Move contracts, check out documentation.
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