Last active
March 5, 2020 11:59
-
-
Save davizalpe/098e25258dea684e0bbeae0b083d7cfe to your computer and use it in GitHub Desktop.
This file contains hidden or 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
```javascript | |
# createWallet.js | |
const Wallet = require('ethereumjs-wallet') | |
const wallet = Wallet.generate(); | |
console.log('0x'+wallet.getAddress().toString('hex')); | |
console.log(wallet.getPublicKey().toString('hex')); | |
console.log(wallet.getPrivateKey().toString('hex')); | |
``` | |
```javascript | |
# importWallet.js | |
const Wallet = require('ethereumjs-wallet') | |
const privateKey = process.env.YOUR_PRIVATE_KEY; | |
const wallet = Wallet.fromPrivateKey(Buffer.from(privateKey, 'hex')); | |
console.log('0x'+wallet.getAddress().toString('hex')); | |
``` | |
```javascript | |
# createHD.js | |
const bip39 = require("bip39"); | |
const mnemonic = bip39.generateMnemonic(); //generates string | |
const seed = bip39.mnemonicToSeed(mnemonic); //creates seed buffer | |
console.log(mnemonic.toString()); | |
``` | |
```javascript | |
# importHD.js | |
const hdkey = require('ethereumjs-wallet/hdkey') | |
const bip39 = require("bip39"); | |
const mnemonic = process.env.MNEMONIC_SEED | |
const path = "m/44'/60'/0'/0/0"; | |
const hdWallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic)); | |
for(let i = 0; i < 10; i++) { | |
const wallet = hdWallet.derivePath(`m/44'/60'/0'/0/${i}`).getWallet(); | |
const address = wallet.getAddress(); | |
console.log('0x' + address.toString('hex')); | |
console.log(wallet.getPrivateKey().toString('hex')); | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment