<p>A very simple way is to use <a href="https://en.bitcoin.it/wiki/Vanitygen" rel="nofollow"><code>Vanitygen</code></a> with the following command:</p>

<pre><code>vanitygen -k -o output.txt -s seeds.txt 1
</code></pre>

<ul>
<li><code>-k</code> keeps it going after it finds a hit</li>
<li><code>-o output.txt</code> will write the key pairs to the file <code>output.txt</code></li>
<li><code>-s seeds.txt</code> will let you have different seeds. Create this on beforehand</li>
<li><code>1</code> is the pattern Vanitygen will look for. Because all addresses start with <code>1</code>, every hit will be good. Also nice if you want to have nice addresses, like <code>1Hristo</code> or something. Keep in mind that it will reduce speed ALOT.</li>
</ul>

<p>Vanitygen creates about 300 kKey/second on my 2010 MBP CPU. With <code>oclvanitygen</code> it is around 750 kKeys/second. The <code>output.txt</code> will reduce the speed a bit, but it will not take a lifetime. I am not on a computer right now on which I can test the command, but it <em>should</em> work. </p>

<p>This will generate key pairs until infinity. If you really want to have exactly 1000000 (or any other number) pairs, try something with a bash for-loop, and something like </p>

<pre><code>vanitygen 1 &gt;&gt; output.txt
</code></pre>

<p>Again, I cannot check this right now, so I don't know how the pairs will be in the <code>output.txt</code>, but it should be appended and readable for you. </p>

CC BY-SA 3.0
2014-07-14T14:18:20.783Z
@HristoHristov Out of curiosity: did you use this? If yes, how fast did it go? Was it with ~ 200kKeys/seconds?
Mathias711
CC BY-SA 3.0
2014-07-14T14:43:18.497Z
It's 1.99 Mkey/s for hard prefixes, but in the case with "1" and writing to output.txt, I'm getting 1K keys per second, which is good enough. It's slower of course, because I guess it's faster to discard an invalid key early, instead of completing the calculations for each key. Anyway, it's fast enough for this case.
Hristo Hristov
CC BY-SA 3.0
2014-07-14T14:52:54.290Z
That's a slowing factor I didn't expect. For what I understood from vanitygen is that it creates a key, computes the address and checks it. If good, print the key pair and create new pair (with `-k` option). If false, create new key. That printing doesnt cost that much resources I imagined. But thanks for the numbers :)
Mathias711
CC BY-SA 3.0
2014-07-14T17:54:11.430Z
That slowdown is not at all surprising to me: printing and writing to a file is expensive business, especially if the app was only expecting to rarely print values. If it were useful, a version of vanitygen (addressgen?) could be created optimized for this use case. But since it's good enough as-is...
Tim S.
CC BY-SA 3.0
2014-07-14T10:35:34.010Z
2014-07-14T10:35:34.010Z
Mathias711
<p>You can use <a href="https://bitcoinj.github.io/" rel="nofollow noreferrer">bitcoinj</a> — a thoroughly tested Java library written by a google employee as a 20% project. It is used by some wallet apps, such as samurai wallet, bitcoin wallet, greenbits (mycelium plans to migrate to bitcoinj).</p>

<ol>
<li>Clone the project from <a href="https://github.com/bitcoinj/bitcoinj.git" rel="nofollow noreferrer">https://github.com/bitcoinj/bitcoinj.git</a></li>
<li>Install <a href="https://maven.apache.org/" rel="nofollow noreferrer">maven</a> if missing (e.g. <code>brew install maven</code> on osx or <code>apt install maven</code> on linux), and then sync the project so that all dependencies are satisfied: <code>mvn install</code> (from the project folder).</li>
<li>Use the following code to generate your private/public key pairs.</li>
</ol>



<pre><code>import org.bitcoinj.core.Address;
import org.bitcoinj.core.DumpedPrivateKey;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.NetworkParameters;

public class GeneratePrivateKey {

    public static void main(String[] args) {

        for (int i=0; i&lt;10000; i++) {
            ECKey key = new ECKey();
            DumpedPrivateKey privKey = key.getPrivateKeyEncoded(NetworkParameters.prodNet());
            System.out.println("private key: " + privKey.toBase58());
            Address pubAddress = new Address(NetworkParameters.prodNet(), key.getPubKeyHash());
            System.out.println("public key: " + pubAddress.toBase58());
            System.out.println("--------------------------------");
        }
    }
}
</code></pre>

CC BY-SA 3.0
2017-12-15T21:17:15.117Z
2017-12-15T22:38:27.137Z
2017-12-15T22:38:27.137Z
ccpizza
<p>I want to generate, say 100000 key pairs (address/private key). It should be done offline, without using websites/javascript , with a program on the command line. Of course, the software should use the best way to generate randomness. There is such function on <a href="https://www.bitaddress.org" rel="nofollow">https://www.bitaddress.org</a> , but it's javascript and is not easy to be used by scripts on the command line. Do you know of such software?</p>

CC BY-SA 3.0
2014-07-14T11:08:48.787Z
You might want to consider deterministic wallets instead of generating list of keys. https://en.bitcoin.it/wiki/Deterministic_wallet - this way you could avoid maintaining the list of keys
Mikko Ohtamaa
CC BY-SA 3.0
2014-07-14T14:47:29.497Z
Thanks for the suggestion, but in this case I actually need the list in order to match addresses to users and spend the amounts.
Hristo Hristov
CC BY-SA 3.0
2014-07-14T18:27:06.993Z
Well you can always use the user id as the deterministic seed :)
Mikko Ohtamaa
CC BY-SA 3.0
2014-07-14T19:35:13.803Z
That would be easily determined ;)
Hristo Hristov
<address-generation>
How to generate a bulk wallet offline with python, java or c++?
Hristo Hristov
# How to generate a bulk wallet offline with python, java or c++?

(Asked by: username_0 on 2014-07-14)

I want to generate, say 100000 key pairs (address/private key). It should be done offline, without using websites/javascript , with a program on the command line. Of course, the software should use the best way to generate randomness. There is such function on <https://www.bitaddress.org> , but it's javascript and is not easy to be used by scripts on the command line. Do you know of such software?

**Tags:** address-generation

> **Comments:**
> **username_1**: You might want to consider deterministic wallets instead of generating list of keys. https://en.bitcoin.it/wiki/Deterministic_wallet - this way you could avoid maintaining the list of keys  
> **username_0**: Thanks for the suggestion, but in this case I actually need the list in order to match addresses to users and spend the amounts.  
> **username_1**: Well you can always use the user id as the deterministic seed :)  
> **username_0**: That would be easily determined ;)  

---

## 2 answers

### Answer by username_2 on 2014-07-14. Score: 3

A very simple way is to use Vanitygen with the following command:
vanitygen -k -o output.txt -s seeds.txt 1


-k keeps it going after it finds a hit
-o output.txt will write the key pairs to the file output.txt
-s seeds.txt will let you have different seeds. Create this on beforehand
1 is the pattern Vanitygen will look for. Because all addresses start with 1, every hit will be good. Also nice if you want to have nice addresses, like 1Hristo or something. Keep in mind that it will reduce speed ALOT.

Vanitygen creates about 300 kKey/second on my 2010 MBP CPU. With oclvanitygen it is around 750 kKeys/second. The output.txt will reduce the speed a bit, but it will not take a lifetime. I am not on a computer right now on which I can test the command, but it should work. 
This will generate key pairs until infinity. If you really want to have exactly 1000000 (or any other number) pairs, try something with a bash for-loop, and something like 
vanitygen 1 >> output.txt

Again, I cannot check this right now, so I don't know how the pairs will be in the output.txt, but it should be appended and readable for you.

> **Comments:**
> **username_2**: @HristoHristov Out of curiosity: did you use this? If yes, how fast did it go? Was it with ~ 200kKeys/seconds?  
> **username_0**: It's 1.99 Mkey/s for hard prefixes, but in the case with "1" and writing to output.txt, I'm getting 1K keys per second, which is good enough. It's slower of course, because I guess it's faster to discard an invalid key early, instead of completing the calculations for each key. Anyway, it's fast enough for this case.  
> **username_2**: That's a slowing factor I didn't expect. For what I understood from vanitygen is that it creates a key, computes the address and checks it. If good, print the key pair and create new pair (with `-k` option). If false, create new key. That printing doesnt cost that much resources I imagined. But thanks for the numbers :)  
> **username_3**: That slowdown is not at all surprising to me: printing and writing to a file is expensive business, especially if the app was only expecting to rarely print values. If it were useful, a version of vanitygen (addressgen?) could be created optimized for this use case. But since it's good enough as-is...  

---

### Answer by username_4 on 2017-12-15. Score: 0

You can use bitcoinj — a thoroughly tested Java library written by a google employee as a 20% project. It is used by some wallet apps, such as samurai wallet, bitcoin wallet, greenbits (mycelium plans to migrate to bitcoinj).

Clone the project from https://github.com/bitcoinj/bitcoinj.git
Install maven if missing (e.g. brew install maven on osx or apt install maven on linux), and then sync the project so that all dependencies are satisfied: mvn install (from the project folder).
Use the following code to generate your private/public key pairs.

import org.bitcoinj.core.Address;
import org.bitcoinj.core.DumpedPrivateKey;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.NetworkParameters;

public class GeneratePrivateKey {

    public static void main(String[] args) {

        for (int i=0; i<10000; i++) {
            ECKey key = new ECKey();
            DumpedPrivateKey privKey = key.getPrivateKeyEncoded(NetworkParameters.prodNet());
            System.out.println("private key: " + privKey.toBase58());
            Address pubAddress = new Address(NetworkParameters.prodNet(), key.getPubKeyHash());
            System.out.println("public key: " + pubAddress.toBase58());
            System.out.println("--------------------------------");
        }
    }
}


---

