javascript - error "fromMnemonic()"Create ether wallet - Stack Overflow
Last active
July 9, 2023 01:54
-
-
Save dentropy/788e17cc52d755527cef199d11b38a83 to your computer and use it in GitHub Desktop.
Load Mnemonic into EthersJS using DOTENV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config(); | |
const ethers = require('ethers'); | |
async function main() { | |
// Load the mnemonic from the .env file | |
let mnemonic = process.env.MNEMONIC; | |
let mnemonic_path = process.env.MNEMONIC_PATH | |
if (mnemonic_path == ''){ | |
mnemonic_path = "m/44'/60'/0'/0" | |
} | |
if (!mnemonic) { | |
throw new Error('MNEMONIC not found in .env file'); | |
} | |
const wallet = ethers.Wallet.fromMnemonic(mnemonic, mnemonic_path); | |
console.log('Wallet address:', wallet.address); | |
} | |
main().catch((error) => { | |
console.error('Error:', error); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment