MetaMask 连接 Ganache
2025/8/1大约 1 分钟
MetaMask 连接 Ganache
remix 编译后怎么都部署不到 ganache 上,最后找到是编译器的问题。从而发现 ganache 在内的 Truffle Suit 已经不被维护了 😅。 Truffle Suite 已进入“Sunset”(停用)阶段。这是由 Truffle 的母公司 ConsenSys 于 2024 年宣布的决定。
TypeError: Cannot read private member xxx from an object whose class did not declare it
问题发生场景 在 vue3 中使用 reactive 响应式转换一个带有私有属性的对象。 Cannot read private member #notReady from an object whose class did not declare it
大致原因 在 js 中,代理 Proxy 和类的私有属性无法公用,而 vue3 的响应式是基于代理的。
Vue 3 响应式与 ethers.js 私有属性问题
- 问题: Vue 3 的 Proxy 响应式系统无法访问 ethers.js 的私有属性 #notReady
- 原因: ES6 Proxy 和类私有属性无法共存
修复方案:
- 使用 shallowRef - 避免深度响应式代理
- 使用 markRaw - 将 ethers 对象标记为非响应式
- 组合使用 - 确保完全避免响应式干扰
关键修改:
// 导入必要的 Vue 函数 import { markRaw, shallowRef } from 'vue'
// 使用 shallowRef 声明 const provider = shallowRef(null) const signer = shallowRef(null) const contract = shallowRef(null)
// 创建时使用 markRaw const ethersProvider = markRaw(new ethers.BrowserProvider(window.ethereum)) const ethersSigner = markRaw(await ethersProvider.getSigner()) const ethersContract = markRaw(new ethers.Contract(...))