Developers
開發者中心
在 MAGNE L1 與 M Hash L2 上進行開發。獲取網絡配置、開發者工具與文檔。
magne-cli — developer
$ magne dev init
✓ MAGNE Dev Environment
network: MAGNE L1 + M Hash L2
chain-id: 20250810 (L1) / 20250827 (L2)
tools: Hardhat, Foundry, ethers.js
$ magne dev start
✓ Connected to testnet
rpc: https://rpc.testnet.magicalhash.com
網絡配置
MAGNE L1 與 M Hash L2 測試網的當前配置參數
MAGNE L1 測試網
測試網已上線| 鏈 ID | 20250810 |
| 代幣符號 | MHA |
| RPC | https://rpc.testnet.magicalhash.com |
| 瀏覽器 | explorer.testnet.magicalhash.com |
備註:測試網參數可能會變更。請勿將測試網端點用於生產部署。測試網代幣無貨幣價值。
快速入門
四個步驟開始在 MAGNE 上構建
STEP 01
將網絡添加到錢包
使用上述網絡配置將 MAGNE L1 或 M Hash L2 測試網添加到 MetaMask 或您首選的 Web3 錢包。
鏈 ID: 20250810 (L1) / 20250827 (L2)
STEP 02
獲取測試網 MHA
訪問水龍頭獲取測試網 MHA 代幣,用於開發和測試。
水龍頭開發中 — 聯繫 @MagneAI
STEP 03
部署合約
使用 Hardhat、Foundry 或您首選的開發框架將智能合約部署到測試網。
npx hardhat run scripts/deploy.js --network magne-l1
STEP 04
構建 DApp
使用 ethers.js、web3.js 或 viem 將您的 DApp 連接到 MAGNE 網絡。
ethers.JsonRpcProvider('https://rpc.testnet.magicalhash.com')
開發者工具
在 MAGNE 網絡上構建所需的工具與服務
代碼示例
常用整合示例
ethers.js 連接
const { ethers } = require('ethers');
const provider = new ethers.JsonRpcProvider(
'https://rpc.testnet.magicalhash.com'
);
const wallet = new ethers.Wallet(
process.env.TESTNET_PRIVATE_KEY,
provider
);
const balance = await provider.getBalance(wallet.address);
console.log('Balance:', ethers.formatEther(balance), 'MHA');
// 安全:使用專用測試錢包。
// 切勿在前端代碼或公共倉庫中暴露私鑰。
Hardhat 配置
// hardhat.config.js
module.exports = {
networks: {
'magne-l1': {
url: 'https://rpc.testnet.magicalhash.com',
chainId: 20250810,
},
'magne-l2': {
url: 'https://l2-rpc.testnet.magicalhash.com',
chainId: 20250827,
},
},
};