Wanted: Generate a 12 word seed phrase for testing

I want an easy mechanism to generate a 12 word seed phrase for testing.

Ideally that I can run via npx

I currently use MyCrypto but would like to do this from the command line.

Suggestions appreciated.

Hi @abcoathup

i use some libraries for this.

For Node/JavaScript:

import bip39 from 'bip39';

const mnemonic = bip39.generateMnemonic();

With this you can easily create a CLI command creating new mnemonics :slight_smile:

More info can be found here:

1 Like

And for PHP using bitwasp/bitcoin:

/**
 * @return string
 * @throws \BitWasp\Bitcoin\Exceptions\RandomBytesFailure
 */
public function generateMnemonic()
{
    $random = new Random();
    $entropy = $random->bytes(Bip39Mnemonic::MAX_ENTROPY_BYTE_LEN);

    $bip39 = MnemonicFactory::bip39();

    $mnemonic = $bip39->entropyToMnemonic($entropy);

    return $mnemonic;
}
1 Like

I’ve just created a CLI tool for this.

npm install -g mnemonics

It will create a seed and print out 12 words phrase onto the console.

If you use a mac, you can easily put it into the clipboard for convinience

mnemonics | pbcopy

I made an alias for myself:

alias m=mnemonics

everytime I type “m” in terminal, i get new mnemonics :slight_smile:

4 Likes

Awesome @itinance

Ideally I want to run without having to install anything.
e.g.

$ npx cowsay awesome
npx: installed 10 in 8.514s
 _________
< awesome >
 ---------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

When I do the same for mnemonics I get an error:

$ npx mnemonics
npx: installed 15 in 3.739s
EISDIR: illegal operation on a directory, read

Hm… i’m not familiar with npx and don’t know how it will deal with paths and files. However, pull requests are welcome :slight_smile:
You could create an Issue on the github repository.

1 Like

npx is awesome, it is an npm package runner, and is part of npm.

As well as running locally installed packages, it is great when using a package such as mnemonics that aren’t run very frequently, as you can run it without installing anything.

I have created an issue https://github.com/itinance/mnemonics/issues/1 :smile:

1 Like