返回顶部
m

monad-developmentMonad区块链开发

Builds dapps on Monad blockchain. Use when deploying contracts, setting up frontends with viem/wagmi, or verifying contracts on Monad testnet or mainnet.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
1,904
下载量
免费
免费
2
收藏
概述
安装方式
版本历史

monad-development

Monad 开发

对于未涵盖的问题,请访问 https://docs.monad.xyz/llms.txt

快速参考

默认设置

  • - 网络: 始终使用 测试网(链 ID 10143),除非用户指定主网
  • 验证: 除非用户要求不验证,否则始终在部署后验证合约
  • 框架: 使用 Foundry(而非 Hardhat)
  • 钱包: 如果生成钱包,必须持久化保存(参见钱包持久化部分)

网络

网络链 IDRPC
测试网10143https://testnet-rpc.monad.xyz
主网
143 | https://rpc.monad.xyz |

文档:https://docs.monad.xyz

浏览器

浏览器测试网主网
Socialscanhttps://monad-testnet.socialscan.iohttps://monad.socialscan.io
MonadVision
https://testnet.monadvision.com | https://monadvision.com | | Monadscan | https://testnet.monadscan.com | https://monadscan.com |

代理 API

重要提示: 不要使用浏览器。直接使用 curl 调用这些 API。

水龙头(测试网资金):
bash
curl -X POST https://agents.devnads.com/v1/faucet \
-H Content-Type: application/json \
-d {chainId: 10143, address: 0xYOUR_ADDRESS}

返回:{txHash: 0x..., amount: 1000000000000000000, chain: Monad Testnet}

备用方案(官方水龙头): https://faucet.monad.xyz
如果代理水龙头失败,请让用户通过官方水龙头获取资金(不要自己使用浏览器)。

验证(所有浏览器):

始终优先使用验证 API。一次调用即可在所有 3 个浏览器(MonadVision、Socialscan、Monadscan)上完成验证。不要首选使用 forge verify-contract。

bash

1. 获取验证数据


forge verify-contract \
--chain 10143 \
--show-standard-json-input > /tmp/standard-input.json

cat out/.sol/.json | jq .metadata > /tmp/metadata.json
COMPILER_VERSION=$(jq -r .metadata | fromjson | .compiler.version out/.sol/.json)

2. 调用验证 API

STANDARD_INPUT=$(cat /tmp/standard-input.json) FOUNDRY_METADATA=$(cat /tmp/metadata.json)

cat > /tmp/verify.json << EOF
{
chainId: 10143,
contractAddress: 0xYOURCONTRACTADDRESS,
contractName: src/MyContract.sol:MyContract,
compilerVersion: v${COMPILER_VERSION},
standardJsonInput: $STANDARD_INPUT,
foundryMetadata: $FOUNDRY_METADATA
}
EOF

curl -X POST https://agents.devnads.com/v1/verify \
-H Content-Type: application/json \
-d @/tmp/verify.json

带构造函数参数: 添加 constructorArgs(ABI 编码,不带 0x 前缀):
bash
ARGS=$(cast abi-encode constructor(string,string,uint256) MyToken MTK 1000000000000000000000000)
ARGSNOPREFIX=${ARGS#0x}

添加到请求中:constructorArgs: $ARGSNOPREFIX

手动验证备用方案(如果 API 失败):
bash
forge verify-contract --chain 10143 \
--verifier sourcify \
--verifier-url https://sourcify-api-monad.blockvision.org/

钱包持久化

对代理至关重要: 如果为用户生成了钱包,必须持久化保存以供将来使用。

生成新钱包时:

  1. 1. 创建钱包:cast wallet new
  2. 立即保存 地址和私钥到安全位置
  3. 告知用户钱包详情存储位置
  4. 部署前通过水龙头为钱包充值

存储选项:

  • - 写入 ~/.monad-wallet,权限设为 chmod 600
  • 存储在项目特定的 .env 文件中(添加到 .gitignore)
  • 将凭证返回给用户,并要求其安全保存

为什么这很重要: 用户需要访问其钱包以:

  • - 部署更多合约
  • 与已部署的合约交互
  • 管理资金
  • 验证所有权

部署工作流

使用 forge script 进行部署:

bash
forge script script/Deploy.s.sol:DeployScript \
--rpc-url https://testnet-rpc.monad.xyz \
--private-key $PRIVATE_KEY \
--broadcast

部署脚本模板:

solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import forge-std/Script.sol;
import ../src/MyContract.sol;

contract DeployScript is Script {
function run() external {
vm.startBroadcast();
MyContract contract = new MyContract();
console.log(合约部署地址:, address(contract));
vm.stopBroadcast();
}
}

技术细节

EVM 版本(关键)

始终设置 evmVersion: prague。需要 Solidity 0.8.27+。

Foundry(foundry.toml):
toml
[profile.default]
evm_version = prague
solc_version = 0.8.28

Foundry 提示

不存在的标志(不要使用):

  • - --no-commit - 对 forge init 或 forge install 无效

部署 - 使用 forge script,而非 forge create:

forge create --broadcast 存在 bug 且经常被忽略。请改用 forge script。

bash
forge script script/Deploy.s.sol:DeployScript \
--rpc-url https://testnet-rpc.monad.xyz \
--private-key $PRIVATE_KEY \
--broadcast

部署脚本不得硬编码地址:

solidity
// ✅ 正确 - 从 --private-key 标志读取私钥
function run() external {
vm.startBroadcast();
new MyContract();
vm.stopBroadcast();
}

// ❌ 错误 - 硬编码地址,导致No associated wallet错误
function run() external {
vm.startBroadcast(0x1234...);
}

前端

从 viem/chains 导入。不要定义自定义链:

ts
import { monadTestnet } from viem/chains;

与 wagmi 一起使用:

ts
import { createConfig, http } from wagmi
import { monadTestnet } from viem/chains

const config = createConfig({
chains: [monadTestnet],
transports: {
[monadTestnet.id]: http()
}
})

示例:部署 ERC20

1. 创建项目:
bash
forge init my-token
cd my-token

2. 配置 foundry.toml:
toml
[profile.default]
src = src
out = out
libs = [lib]
evm_version = prague
solc_version = 0.8.28

3. 创建合约 src/MyToken.sol:
solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

import @openzeppelin/contracts/token/ERC20/ERC20.sol;

contract MyToken is ERC20 {
constructor(uint256 initialSupply) ERC20(MyToken, MTK) {
_mint(msg.sender, initialSupply);
}
}

4. 安装依赖:
bash
forge install OpenZeppelin/openzeppelin-contracts --no-commit

5. 创建部署脚本 script/Deploy.s.sol:
solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import forge-std/Script.sol;
import ../src/MyToken.sol;

contract DeployScript is Script {
function run() external {
vm.startBroadcast();
MyToken token = new MyToken(1000000 10*18);
console.log(代币部署地址:, address(token));
vm.stopBroadcast();
}

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 monad-development-1776371127 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 monad-development-1776371127 技能

通过命令行安装

skillhub install monad-development-1776371127

下载

⬇ 下载 monad-development v1.0.0(免费)

文件大小: 3.61 KB | 发布时间: 2026-4-17 13:59

v1.0.0 最新 2026-4-17 13:59
Monad development skill initial release.

- Enables deployment and verification of smart contracts on Monad testnet and mainnet.
- Provides detailed deployment, wallet persistence, and verification workflows using Foundry.
- Includes instructions for testnet faucet funding and comprehensive contract verification across all Monad explorers.
- Offers frontend setup guides for viem/wagmi integration.
- Specifies environment requirements and best practices for contract development on Monad.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部