Skip to main content

Deploying a Contract on Moonchain

CAUTION

Make sure you are using a test/throwaway wallet, to be save. Never reveal the private key of your main wallet!

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

Prerequisites

Steps

Create a Project with Foundry

To scaffold a new Foundry project, run:

forge init hello_foundry $$ cd hello_foundry

Deploy the Contract

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

Deploy the contract located at src/Counter.sol:

forge create --rpc-url https://geneva-rpc.moonchain.com --private-key YOUR_PRIVATE_KEY src/Counter.sol:Counter
INFO

If you encounter an error --> ERROR: (Code: -32000, message: contract creation code storage out of gas, data: None), consider deploying using Remix IDE.

View Your Contract

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

pending state is not available

Due to the removal of the pending block tag in Taiko 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 Taiko.