Deploy Smart Contracts on MAGNE Testnets

Guide for developers to deploy test smart contracts on MAGNE L1 and M Hash L2 testnets using Hardhat or Foundry.

1 Overview

Testnet Only β€” This guide is for testnet deployment only. MAGNE L1 Testnet and M Hash L2 Testnet are EVM-compatible environments for developer experimentation. Testnet tokens have no monetary value. Network parameters may change as testing progresses.

  • MAGNE L1 and M Hash L2 are EVM-compatible networks
  • Works with standard Ethereum development tools
  • Deploy Solidity smart contracts for testing
  • Verify contracts on block explorers

Network Parameters

MAGNE L1 Testnet

RPC URLhttps://rpc.testnet.magicalhash.com
Chain ID20250810
SymbolMHA
Explorerhttps://explorer.testnet.magicalhash.com

M Hash L2 Testnet

RPC URLhttps://l2-rpc.testnet.magicalhash.com
Chain ID20250827
SymbolMHA
Explorerhttps://l2-explorer.testnet.magicalhash.com

Hardhat Deployment

1. Install Hardhat

npm init -y
npm install --save-dev hardhat
npx hardhat init

2. Configure hardhat.config.js

require("@nomicfoundation/hardhat-ethers");

module.exports = {
  solidity: "0.8.20",
  networks: {
    'magne-l1': {
      url: "https://rpc.testnet.magicalhash.com",
      chainId: 20250810,
    },
    'magne-l2': {
      url: "https://l2-rpc.testnet.magicalhash.com",
      chainId: 20250827,
    },
  },
};

3. Create .env File

# Never commit this file to version control
TESTNET_PRIVATE_KEY=your_test_wallet_private_key
L1_RPC_URL=https://rpc.testnet.magicalhash.com
L2_RPC_URL=https://l2-rpc.testnet.magicalhash.com

Security

Use a dedicated test wallet. Never use wallets holding real assets. Never commit .env files or private keys to public repositories.

4. Deploy Contract

const hre = require("hardhat");

async function main() {
  const HelloMagne = await hre.ethers.getContractFactory("HelloMagne");
  const contract = await HelloMagne.deploy("Hello MAGNE!");
  await contract.deployed();
  console.log("Contract deployed to:", contract.address);
}

main().catch((error) => {
  console.error(error);
  process.exit(1);
});

Run deployment:

L1_DEPLOY:
npx hardhat run scripts/deploy.js --network magne-l1

L2_DEPLOY:
npx hardhat run scripts/deploy.js --network magne-l2

Foundry Deployment

1. Install Foundry

curl -L https://foundry.paradigm.xyz | bash
foundryup

2. Create Project

forge init my-magne-contract
cd my-magne-contract

3. Set Environment

export TESTNET_PRIVATE_KEY=your_test_wallet_private_key
export L1_RPC_URL=https://rpc.testnet.magicalhash.com
export L2_RPC_URL=https://l2-rpc.testnet.magicalhash.com

4. Create Deployment Script

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "forge-std/Script.sol";
import "../src/HelloMagne.sol";

contract DeployScript is Script {
    function run() external {
        vm.broadcast();
        new HelloMagne("Hello MAGNE!");
    }
}

5. Deploy

L1_DEPLOY:
forge script script/Deploy.s.sol:DeployScript --rpc-url $L1_RPC_URL --broadcast --private-key $TESTNET_PRIVATE_KEY

L2_DEPLOY:
forge script script/Deploy.s.sol:DeployScript --rpc-url $L2_RPC_URL --broadcast --private-key $TESTNET_PRIVATE_KEY

Security

Use a dedicated test wallet. Never expose private keys in scripts or environment variables in production frontends.

Sample Contract

HelloMagne.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract HelloMagne {
    string public message;

    constructor(string memory initialMessage) {
        message = initialMessage;
    }

    function setMessage(string calldata newMessage) external {
        message = newMessage;
    }
}

This contract is for testing and educational purposes only. Review and audit any contract before using in production environments.

Verify Deployment

  • Check explorer: View your contract address on the block explorer
  • Read contract: Call view functions to confirm deployment
  • Write functions: Test state-changing transactions with small values
  • Save addresses: Record deployed contract addresses for your application

Troubleshooting

RPC timeout

Check your internet connection. If the RPC endpoint is under maintenance, wait and retry. Try the other testnet RPC as backup.

Chain ID mismatch

Ensure you entered the correct Chain ID: 20250810 (L1) or 20250827 (L2). Remove and re-add the network if needed.

Insufficient testnet MHA

Ensure you have testnet tokens. Contact @MagneAI for testnet token requests.

Deployment transaction pending

Testnet transactions may take longer during high traffic. Check the explorer for pending status. L2 typically confirms faster than L1.

Compiler version mismatch

Ensure your Solidity compiler version matches the pragma in your contract. Check for warnings in Hardhat/Foundry output.

Nonce too low

Reset your wallet's nonce or wait for pending transactions to complete. Some wallets allow nonce reset in settings.

⚠️ Security Notes

Use a dedicated test wallet. Never use wallets holding real assets for testnet development.

Never commit private keys, seed phrases, or .env files to version control or public repositories.

Testnet tokens have no monetary value. Smart contract examples are for testing and educational purposes only.

MAGNE.AI team will never ask for your private keys or seed phrases.