Deploying Solidity Contracts on Movement using Foundry and Fractal
This tutorial will walk you through deploying a Solidity smart contract on M1 using Fractal and Foundry.
Our toolkit
What is Foundry?
Foundry is a powerful smart contract development toolchain for Ethereum Virtual Machines.
What is Fractal?
Fractal is Movement Labs' interpreter 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 MOVE tokens
Fund an EVM wallet address with some MOVE
tokens using our faucet. Another method to get get MOVE
is to bridge from M1 to your EVM wallet using our bridge. To connect to our testnet and check if you have received the MOVE
tokens, you can take the following steps:
Add the move-evm network to your EVM-compatible wallet.
Property Value Network Name
mevm
Network RPC
https://mevm.devnet.m1.movementlabs.xyz/v1/
Network ID
0x0150
Network Currency
MOVE
Ensure you have switched your Wallet network to the network added above, i.e.,
move-evm
.
Step 2: Setup your Foundry project
If you don't have a specific directory for your project, create one and access it:
Open it in your favorite editor. Here we are using VSCode
Initiate your Foundry project. This will create a foundry.toml, a README.md and a few folders, lib, script, src and test.
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 MOVE
. 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.
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 src/
open the file Counter.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 number
and two functions, setNumber
and increment
to set the value of number
and increment it respectively.
Now, under script
, open the file Counter.s.sol
. 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 src/Counter.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 Foundry. 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 Foundry. To do so, we will write another script. Under script
, create a new file Interact.s.sol
and add the following contents:
Make sure to replace <counterAddress>
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 successful, 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