Deploying A Contract
Deploying a Contract on Moonchain
Section titled “Deploying a Contract on Moonchain”This guide will help you deploy a smart contract on Moonchain (Hudson Testnet) using Foundry.
Prerequisites
Section titled “Prerequisites”- Foundry is installed.
- You have the private key handy to an account that has
Test $MCH Tokens
on Moonchain Hudson (to pay the transaction fee for deploying the contract). - Have some Test $MCH Tokens on Moonchain Hudson:
- Request Test $MCH Tokens from the faucet.
Create a Project with Foundry
Section titled “Create a Project with Foundry”To scaffold a new Foundry project, run:
forge init hello_foundry $$ cd hello_foundry
Deploy the Contract
Section titled “Deploy the Contract”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
:
forge create --rpc-url https://Hudson-rpc.mchain.ai --private-key YOUR_PRIVATE_KEY src/Counter.sol:Counter
View Your Contract
Section titled “View Your Contract”Paste the address from the output into the Moonchain Hudson Block Explorer and verify that the contract was deployed.
pending state is not available
Section titled “pending state is not available”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 .