Skip to content

Instantly share code, notes, and snippets.

@davizalpe
Last active March 5, 2020 11:59
Show Gist options
  • Save davizalpe/098e25258dea684e0bbeae0b083d7cfe to your computer and use it in GitHub Desktop.
Save davizalpe/098e25258dea684e0bbeae0b083d7cfe to your computer and use it in GitHub Desktop.
```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