Skip to content

Instantly share code, notes, and snippets.

@dentropy
Last active July 9, 2023 01:54
Show Gist options
  • Save dentropy/788e17cc52d755527cef199d11b38a83 to your computer and use it in GitHub Desktop.
Save dentropy/788e17cc52d755527cef199d11b38a83 to your computer and use it in GitHub Desktop.
Load Mnemonic into EthersJS using DOTENV
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