Skip to content

Deploying A Contract

This guide will help you deploy a smart contract on Moonchain (Hudson Testnet) using Foundry.

To scaffold a new Foundry project, run:

Terminal window
forge init hello_foundry $$ cd hello_foundry

Replace YOUR_PRIVATE_KEY below with your private key that has some Test $MCH Tokens on Moonchain Hudson testnet.

Deploy the contract located at src/Counter.sol:

Terminal window
forge create --rpc-url https://Hudson-rpc.mchain.ai --private-key YOUR_PRIVATE_KEY src/Counter.sol:Counter

Paste the address from the output into the Moonchain Hudson Block Explorer and verify that the contract was deployed.

Due to the removal of the pending block tag in RPC (#6076), if you deploy using Hardhat, you will encounter the issue pending state is not available. Using Foundry can avoid this problem, or you can migrate your Hardhat project to Harsta, harsta which will continue to support .