【问题标题】:Is it possible to check the Connected RPC network in MetaMask using JQuery?是否可以使用 JQuery 在 MetaMask 中检查 Connected RPC 网络?
【发布时间】:2021-10-12 11:01:35
【问题描述】:

在我的 DApp 中,我想检查 MetaMask 是否使用 JQuery 连接到 BSC Minnet RPC 网络。是否可以使用 JQuery 在 MetaMask 中检查 Connected RPC 网络?

提前感谢!

【问题讨论】:

  • JQuery 真的可以做两件事: 1. 影响 DOM(当前网页) 2. 调用 Web 服务。如果您想要做的任何事情都可以通过调用 Web 服务来实现,那么可以。但我不会打扰 JQuery,使用更新的原生 javascript fetch

标签: jquery blockchain ethereum solidity binance-smart-chain


【解决方案1】:

MetaMask 实现了 Ethereum Provider API,因此您可以读取 chainId 属性 (docs)。

if (window?.ethereum?.chainId === "0x38") {
    console.log("currently selected BSC mainnet");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多