In this guide for Solidity developers, you'll learn how easy it is to create an Aptos dApp React frontend and configure your dApp for Movement Network.
Requirements
Make sure to have to have Foundry installed. If using Hardhat, have in mind that you will need to add custom chains.
Setup
We will bootstrap our dapp the following with the command provided by Scaffold-ETH.
npxcreate-eth@latest
Once you have executed the npx create-eth@latest command in your terminal, follow the on-screen instructions to configure your Solidity dApp. You have the option to choose Foundry or Hardhat. We will use Foundry. Choose to install dependencies.
Navigate to your dApp's directory and launch your preferred Integrated Development Environment (IDE). In this guide, we will be using Visual Studio Code (VS Code).
cdyour-dapp-namecode.
Within the project directory, you will encounter several folders and files. Our focus will primarily be on the following:
packages/foundry
packages/nextjs
Deploying a Smart Contract with MEVM
First, it will require some configuration. Navigate to packages/foundry/foundry.toml and change its content to the following:
//SPDX-License-Identifier: MITpragmasolidity >=0.8.0 <0.9.0;// Use openzeppelin to inherit battle-tested implementations (ERC20, ERC721, etc)// import "@openzeppelin/contracts/access/Ownable.sol";/** * A smart contract that allows changing a state variable of the contract and tracking the changes * It also allows the owner to withdraw the Ether in the contract * @author BuidlGuidl */contract YourContract {// State Variablesaddresspublicimmutable owner;stringpublic greeting ="Building Unstoppable Apps!!!";boolpublic premium =false;uint256public totalCounter =0;mapping(address=>uint256) public userGreetingCounter;// Events: a way to emit log statements from smart contract that can be listened to by external partieseventGreetingChange(addressindexed greetingSetter,string newGreeting,bool premium,uint256 value );// Constructor: Called once on contract deployment// Check packages/foundry/deploy/Deploy.s.solconstructor(address_owner) { owner = _owner; }// Modifier: used to define a set of rules that must be met before or after a function is executed// Check the withdraw() functionmodifierisOwner() {// msg.sender: predefined variable that represents address of the account that called the current functionrequire(msg.sender == owner,"Not the Owner"); _; }/** * Function that allows anyone to change the state variable "greeting" of the contract and increase the counters * * @param _newGreeting (string memory) - new greeting to save on the contract */functionsetGreeting(stringmemory_newGreeting) publicpayable {// Print data to the anvil chain console. Remove when deploying to a live network. greeting = _newGreeting; totalCounter +=1; userGreetingCounter[msg.sender] +=1;// msg.value: built-in global variable that represents the amount of ether sent with the transactionif (msg.value >0) { premium =true; } else { premium =false; }// emit: keyword used to trigger an eventemitGreetingChange(msg.sender, _newGreeting, msg.value >0,0); }/** * Function that allows the owner to withdraw all the Ether in the contract * The function can only be called by the owner of the contract as defined by the isOwner modifier */functionwithdraw() publicisOwner { (bool success, ) = owner.call{value:address(this).balance}("");require(success,"Failed to send Ether"); }/** * Function that allows the contract to receive ETH */receive() externalpayable {}}
Now you can run the following command to deploy the prebuilt contract that comes with Scaffold-ETH:
yarndeploy--networkmevm
It should give you a YourContract deployment address which should write to a file that Scaffold-ETH will take and use to generate a Front End for!
Configure Your dApp for MEVM
Head to packages/nextjs/scaffold.config.ts and change targetNetworks to [chain.mevm]:
Sweet, you are pretty much setup. Now you can run the following to run your dApp:
yarnstart
Access your dApp at https://localhost:3000. Ensure MEVM is added to Metamask or your chosen EVM wallet to access all contract functions via http://localhost:3000/debug
Experiment with function calls and value queries.
What dApps will you build on Movement?
Now you know how to configure a Solidity dApp for MEVM.
Check out YourContract logic, try a redeployment by tinkering with it. As a challenge, try modifying the Front End to display the user's greeting and counter!
We can't wait to see what dApps you build and deploy to Movement Network!