Deploy Contracts on Morph
The Morph Holesky Testnet allows anyone to deploy a smart contract on Morph. In this tutorial, you will learn how to deploy a contract on Morph Holesky using common tools for developing on Ethereum.
This demo repo illustrates contract deployment with Hardhat and Foundry.
Deploy contracts with Hardhat
-
Clone the repo and install dependencies:
git clone https://github.com/morph-l2/morph-examples.git
cd contract-deploy-demo
yarn install -
Create a
.env
file following the example.env.example
in the root directory. ChangePRIVATE_KEY
to your own account private key in the.env
. -
Run
yarn compile
to compile the contract. -
Run
yarn deploy:morphTestnet
to deploy the contract on the Morph Holesky Testnet. -
Run
yarn test
for hardhat tests.
Deploy contracts with Foundry
-
Clone the repo:
git clone https://github.com/morph-l2/morph-examples.git
cd contract-deploy-demo -
Install Foundry:
curl -L https://foundry.paradigm.xyz | bash
foundryup -
Run
forge build
to build the project. -
Deploy your contract with Foundry:
forge create --rpc-url https://rpc-testnet.morphl2.io/ \
--value <lock_amount> \
--constructor-args <unlock_time> \
--private-key <private_key> \
--legacy contracts/Lock.sol:Lock<lock_amount>
is the amount of testETH
to be locked in the contract. Try setting this to some small amount, like0.0000001ether
;<unlock_time>
is the Unix timestamp after which the funds locked in the contract will become available for withdrawal. Try setting this to some Unix timestamp in the future, like1714492800
(this Unix timestamp corresponds to May 1, 2024).
For example:
forge create --rpc-url https://rpc-testnet.morphl2.io/ \
--value 0.0000001ether \
--constructor-args 1714492800 \
--private-key a123q123q233q231q231q2q1223q23q11q33q113qq31q31231 \
--legacy contracts/Lock.sol:LockOnce successed, you will see the following message:
Deployer: <Your address>
Deployed to: <Your contract address>
Transaction hash: <The deploy transaction hash>
Questions and Feedback
Thank you for participating in and developing on the Morph Holesky Testnet! If you encounter any issues, join our Discord and find us at #dev-help channel.