手册
主网 Web3Modal 和钱包加固 (Web3modal)
从仅 MetaMask 迁移到 Web3Modal + WalletConnect + Coinbase WalletLink; chainId、gas 和地址强化。
NFT Collection 铸币和主网强化
部分 4 的 4
CBD 全明星和自信的大猩猩薄荷表面:WIP 白名单漏斗、IPFS 元数据、占位符→显示管道以及使用 Web3Modal 强化主网钱包。
主网打破了单一钱包假设
Gorillas 主网 1.8 放弃了 All-Stars/1.4 时代的 window.ethereum.enable() 路径。使用Web3Modal cacheProvider打开; WalletConnect (Infura id) 和自定义 Coinbase WalletLink (chainId: 1) 已添加到providerOptions中。 ConnectWeb3 → ethers Web3Provider → 地址;合约实例现在通过模态提供者进行对话。```text Before (All-Stars / early) window.ethereum only → Web3
After (mainnet 1.8) Web3Modal ├─ WalletConnect (Infura) ├─ WalletLink / Coinbase (chainId 1) └─ injected (MetaMask) ↓ provider → ethers Web3Provider ↓ getNftContract(Web3(provider))
## 第一次提到的概念```text
📦 Web3Modal
Çoklu cüzdan bağlantı UI'si; providerOptions ile WalletConnect/WalletLink enjekte edilir.
📦 WalletConnect
QR / mobil cüzdan köprüsü; Infura (veya RPC) id ister.
📦 WalletLink
Coinbase Wallet connector; appName, networkUrl, chainId ile kurulur.
📦 cacheProvider
Son başarılı provider'ı hatırlama; reconnect UX'i, stale session riski.
```RPC/Infura项目id为配置;剧本中没有保留任何秘密。密钥位于环境中,而不是存储库中。
## 为什么仅 MetaMask 还不够?
登陆FAQ可能还是会说MetaMask;主网用户需要 Coinbase 钱包和移动 WalletConnect。单一注射路径切断漏斗。 1.8 决策:具有模态的多连接器,网络:'mainnet'。```text
User segments
Desktop MetaMask
Mobile WC
Coinbase WalletLink
↓
one ConnectWeb3() API
```## 连接生命周期
ConnectWeb3:web3Modal.connect() → Web3Provider → getAddress。 DisconnectWeb3:clearCachedProvider + provider.disconnect + 重新加载。通过 getNetwork 提供程序读取 netId。合约获取者使用 initialState.provider 建立 Web3.eth.Contract — 遗留的 appWeb3() Infura 后备不应成为主网签名路径。```text
connect → address
getNetwork → chainId check
mint/reveal only if chainId OK
disconnect → clear cache → reload
```## ADR:Web3Modal 作为钱包外观
决定:不要将 mint/reveal utils 直接连接到 window.ethereum;给出模态外观地址和提供者。另外:添加连接器将是产品决策。缺点:ethers + web3 双栈和cacheProvider 过时状态。缓解措施:chainId 在铸造前断言,断开连接时清除缓存。```text
ADR-04 Web3Modal facade
UI → ConnectWeb3 / DisconnectWeb3
Utils → provider from modal state
Guard → chainId === 1 before send
Reject → wrong net / no provider
```## 主网失败剧本
1) 生产中的存根合约地址 — tx 显示为“成功”,状态错误。 2) 网络错误——Rinkeby/Goerli 中的签名、主网供应没有变化。 3)gasPrice:0——mempool 上的价格被低估。 4) ABI 不匹配 — multipleMint/reveal 编码错误。 5) 在客户端捆绑包中嵌入 Pinata/Infura 密钥 — 秘密泄漏(从不提交)。```text
Hardening checklist
✓ real mainnet addresses
✓ chainId === 1 gate
✓ dynamic gas / tip
✓ ABI ↔ deployment lock
✓ secrets in env only
本期最令人困惑的对决```text
❌ window.ethereum yeter, modal lüks ✓ Mainnet dönüşümü için çoklu connector ürün gereksinimidir
❌ cacheProvider = her zaman bağlı kal ✓ Stale provider'ı disconnect + clearCachedProvider ile temizle
❌ Infura/Pinata anahtarlarını constants'a yaz ✓ Anahtarlar env/secret store'da; client'a minimum scope
## 您自己的系统清单
1. 连接后是否断言 chainId === 1?
2.在mint发送之前provider不是null吗?
3.gasPrice: 0 是否停留在生产版本中?
4. nft/reserve/auction 地址彼此不同,与主网地址不同吗?
5. WalletConnect / WalletLink 连接器是否在测试设备上进行了实际测试?
## 本节中需要记住的事情
1. 1.8 迁移:仅限 MetaMask → Web3Modal 多钱包外观。
2. 主网强化包括地址、网络、gas、ABI 和秘密纪律。
3. 断开连接和清除缓存是重新连接 UX 的一部分。
> 连接钱包不是一个功能;在错误的网络上签名是一个无声的生产事件。
FAQ
Frequently asked questions
什么是 Web3Modal?
多钱包连接UI; WalletConnect/WalletLink 注入了providerOptions。
什么是 WalletConnect?
二维码/手机钱包桥; Infura(或 RPC)要求提供 ID。
“window.ethereum 足够了,模式奢华”正确吗?
多连接器是主网转换的产品要求
本节修复了什么?
本节以主网准备清单结束本系列:钱包多样性、网络验证、gas 和地址/ABI 规则。 Gorillas 主网 1.8 放弃了 All-Stars/1.4 时代的 window.ethereum.enable() 路径。使用Web3Modal cacheProvider打开; WalletConnect (Infura id) 和自定义 Coinbase WalletLink (chainId: 1) 已添加到providerOptions中。 ConnectWeb3 → ethers Web3Provider → 地址;合约实例现在通过模态提供者进行对话。
学到的工程原理
- 在单一钱包外观后面获取 Mint 实用程序。
- 每次发送前验证 chainId、地址和gas。
- 从包中删除秘密;在真实设备上验证连接器。
继续阅读
继续阅读
系列中的下一个
占位符 URI 和所有者显示行
在 Mint 中,占位符元数据、uridata 映射、reveal(tokenId, uriHash) 和只有所有者才能打开的reveal surface。
同系列
IPFS(星际文件系统)元数据、铸币和多次铸币
Infura IPFS + Pinata pin、元数据 JSON、mint(tokenId, uri) 和 multipleMint:0.1 ETH × n,750 供应。
同系列
集合登陆和 WIP 白名单漏斗
CBD 全明星薄荷登陆:#GETINTHEWIP、750 个插槽、折扣漏斗和仅限 MetaMask 的薄荷表面如何结合在一起?