如何从独立的 node.js 应用程序使用 ethers.js 连接到 Metamask 钱包?

How can I connect to a Metamask wallet using ethers.js from a standalone node.js application?

我绝对是加密领域的菜鸟,正在尝试学习一些东西,但不知道该怎么做。我看过一些文档谈论 ethers.Wallet.fromMnemonic,但以太币如何知道我的钱包是元掩码钱包?或者,如果钱包提供商无关紧要(是吗?),它如何知道其地址?

然后我想与 BSC 上的流动资金池进行交互有什么不同吗?我的意思是在钱包方面。一个钱包可以在多个网络上使用吗?

谢谢。

var web3 = require("web3")
var ethers = require("ethers")

async function MetaMask() {
    

    privateKey = "Your wallet privateKey";

    account = new ethers.Wallet(privateKey)

    console.log(account)

    //from mnemonic

     mnemonic = "Your Mnemonic"

     const wallet = new ethers.Wallet.fromMnemonic(mnemonic)

     console.log(wallet)

 
}

MetaMaskAddress = MetaMask()