DEV Community

Cover image for Getting Started with Morph SDK and Metamask Integration
Azeez Abidoye
Azeez Abidoye

Posted on

Getting Started with Morph SDK and Metamask Integration

About Morph πŸ€”

Morph is the first optimistic zkEVM Ethereum Layer 2 solution that is perfectly compatible with Ethereum Virtual Machine (EVM). Morph platform is uniquely designed to enhance the blockchain experience, making it more accessible, efficient, and user-friendly for both developers and consumers.

What is Morph SDK? πŸ€·β€β™‚οΈ

Assisting developers in creating DAppsΒ onΒ Morph Layer 2 platform, Morph offers a collection of resources, frameworks, and documentation known as the Morph SDK (Software Development Kit). Developers can implement Morph's exclusive Layer 2 capabilities, such scalability, effective transaction processing, and security, into their apps by using it to make interacting with the Morph blockchain straightforward.

Main Takeaways 🎁

  • Download and configure Metamask wallet
  • Integrate Morph Holesky network into Metamask
  • Get Morph Testnet ethers
  • Initialize a new DApp project with Morph SDK
  • Deploy contract on a Local network
  • Deploy on Morph Holesky Testnet using Forge

Dev Tools πŸ› οΈ

  • Yarn
npm install -g yarn
Enter fullscreen mode Exit fullscreen mode
  • Forge
curl -L https://foundry.paradigm.xyz | bash

Enter fullscreen mode Exit fullscreen mode

Step 1: Metamask download and configuration

Metamask homepage

  • Select Add to Browser to download extension

Add Metamask to browser

  • On Metamask homepage, Agree to Terms of use
  • Select Create a new wallet to create a new wallet

Metamask create wallet

  • Agree and continue
  • Create password for your wallet

    ✍️ Consent to the conditions to continue configuring.

  • Select Create new wallet

  • Secure your wallet

    ✍️ It is highly recommended that you secure your wallet to avoid loss of funds and/or assets.

Step 2: Adding network to Metamask

  • Click the Network dropdown at the top-left corner of Metamask page
  • Turn on Show test networks button

Show test networks on Metamask

  • Visit chainlist.org
  • Check the Include Testnets to load test networks
  • Search for Morph Holesky in the search field
  • Select Connect Wallet on the search result

Chainlist webpage

  • Follow through with the prompts and Approve network integration

Chainlist approve metamask network integration

  • Select Switch network to switch to Morph Holesky network

Step 3: Getting testnet ethers

  • Go to Morph Faucet
  • Input your wallet address into the field
  • Click Send ETH button to receive testnet ethers

Morph faucet

Step 4: Retrieving your Private Key

  • Click the three-stacked-dots at the top-right corner of Metamask page
  • Select Account details

Metamask account details

  • Select Show private key button

Metamask account details

  • Insert your password to grant access

Metamask show private key alert

  • Click and hold Hold to reveal Private Key

Metamask click and hold

  • Copy your Private Key

Metamask private key

Step 5: Create a new DApp project

  • To initialize a new DApp project using Morph SDK, run:
npx @morphl2/create-morph-app@latest
Enter fullscreen mode Exit fullscreen mode

✍️ Give your app a name e.g. my-morph-app and wait for the execution to create a new directory for your project with all the packages installed.

Morph App File Tree: πŸ“š

  • Contracts: This directory contains all of the code for developing smart contracts using either the Foundry or Hardhat frameworks. Both frameworks have been structured to allow for rapid and easy DApp development. For this tutorial, we will focus on the Foundry framework.

  • Frontend: The client-side development code exists in this directory. The frontend has been implemented with NextJs, a React framework. You can customize this by integrating other frontend frameworks.

Step 6: Configure DApp for deployment

  • Open contracts/foundry directory
  • Rename the .env-example to .env
  • Populate the PRIVATE_KEY and RPC_URL information

✍️ Ensure to prefix your Private Key with an 0x to avoid errors

PRIVATE_KEY="0x2fa341ffadoNotCopyf78cfd317cYu3aediot91d16308db8"
RPC_URL="https://rpc-quicknode-holesky.morphl2.io"
Enter fullscreen mode Exit fullscreen mode

Step 7: Compile the contract

  • Navigate to contracts/foundry directory and run:
forge build
Enter fullscreen mode Exit fullscreen mode
  • Result of your compilation should look like this:
[⠊] Compiling...
[⠊] Compiling 25 files with Solc 0.8.27
[β ’] Solc 0.8.27 finished in 933.05ms
Compiler run successful!
Enter fullscreen mode Exit fullscreen mode

Step 8: Deploying contract on a Local network

  • Open a new terminal window to activate the local network
anvil
Enter fullscreen mode Exit fullscreen mode

✍️ This opens a list of ten (10) accounts and their private keys for deployment. Leave the terminal running...

  • Navigate to contracts/foundry directory to continue

  • Before deployment, there is need to simulate the contract

forge script script/Deployer.s.sol:DeployerScript --rpc-url http://127.0.0.1:8545 [private_key]
Enter fullscreen mode Exit fullscreen mode

✍️ You can copy one of the Private Keys provided in the Anvil terminal window for use.

Bonus: πŸ’š Store environment information using Keystore Encryption

  • Run this command to encrypt your private key:
cast wallet import testAccount --interactive
Enter fullscreen mode Exit fullscreen mode

✍️ Follow the prompt and encrypt your private key with a simple password for reusability.

  • Finally, run the following command to deploy on local network
forge script script/Deployer.s.sol:DeployerScript --rpc-url http://127.0.0.1:8545 --broadcast --sender [account_address] --account testAccount 
Enter fullscreen mode Exit fullscreen mode

⚠️ For this command to execute, it will request for the password you created to encrypt your private key.

✍️ Remember, your encrypted private key has been linked with the right account. Copy the account that tallies with your private key from the Anvil terminal window.

Step 9: Deploying contract on Morph Holesky testnet

  • Import the configured .env information into the CLI
source .env
Enter fullscreen mode Exit fullscreen mode
  • Simulate the smart contract
forge script script/Deployer.s.sol:DeployerScript --rpc-url $RPC_URL
Enter fullscreen mode Exit fullscreen mode
  • Simulation result should look like this:
[⠊] Compiling...
No files changed, compilation skipped
Script ran successfully.

== Return ==
0: contract MyToken 0x90193C961A926261B756D1E5bb255e67ff9498A1

## Setting up 1 EVM.

==========================

Chain 2810

Estimated gas price: 0.202 gwei

Estimated total gas used for script: 747926

Estimated amount required: 0.000151081052 ETH

==========================

SIMULATION COMPLETE. To broadcast these transactions, add --broadcast and wallet configuration(s) to the previous command. See forge script --help for more.
Enter fullscreen mode Exit fullscreen mode
  • Run the following command to deploy on Morph Holesky testnet:
forge script script/Deployer.s.sol:DeployerScript --rpc-url $RPC_URL  --broadcast --private-key $PRIVATE_KEY --legacy
Enter fullscreen mode Exit fullscreen mode
  • Here is what your deployment result would look like:
[⠊] Compiling...
No files changed, compilation skipped
Script ran successfully.

== Return ==
0: contract MyToken 0x7afC2B995741dCb2e6606f577c99737612763127

## Setting up 1 EVM.

==========================

Chain 2810

Estimated gas price: 0.201 gwei

Estimated total gas used for script: 747926

Estimated amount required: 0.000150333126 ETH

==========================

##### 2810
βœ…  [Success]Hash: 0x1b10883e5da2f07548c5fc4c57f9f257be44b1157bf161f9c1650a73698445e4
Contract Address: 0x7afC2B995741dCb2e6606f577c99737612763127
Block: 11677316
Paid: 0.00011567751 ETH (575510 gas * 0.201 gwei)

βœ… Sequence #1 on 2810 | Total Paid: 0.00011567751 ETH (575510 gas * avg 0.201 gwei)


==========================

ONCHAIN EXECUTION COMPLETE & SUCCESSFUL.
Enter fullscreen mode Exit fullscreen mode
  • Take note of your balance on Metamask

Metamask balance

Morph block explorer

What we have covered: πŸŽ‰

βœ… Download and configure Metamask wallet
βœ… Integrate Morph Holesky network into Metamask
βœ… Get Morph Testnet ethers
βœ… Initialize a new DApp project with Morph SDK
βœ… Store information using Keystore Encryption
βœ… Deploy contract on a Local network
βœ… Deploy on Morph Holesky Testnet using Forge
βœ… Verify contract with Morph explorer

Conclusion

In this tutorial, we covered the fundamental concepts required to quickly and effortlessly build on the Morph blockchain. The process of developing a full stack decentralized application utilizing one of the Ethereum development frameworks begins with the installation and configuration of Metamask. A straightforward and instructive deployment to test and local networks was demonstrated. This article provides comprehensive guidelines for creating a seamless DApp on the Morph blockchain.

Top comments (0)