Deploying a Contract on Moonchain
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
- Foundry is installed.
- You have the private key handy to an account that has
Test $MXC Tokens
on Moonchain Geneva (to pay the transaction fee for deploying the contract). - Have some Test $MXC Tokens on Moonchain Geneva:
- Request Test $MXC Tokens from the faucet.
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
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.