Skip to content
Advertisement

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

I can’t figure out how to do this. I have seen some documentation talking about ethers.Wallet.fromMnemonic, but how does ethers know my wallet is a metamask one? Or, if the wallet provider is irrelevant (is it?) how does it know its address?

Does it make any difference that I want to then interact with a liquidity pool on BSC? I mean in terms of the wallet. Can a wallet be used on multiple networks?

Advertisement

Answer

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()
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement