<p>First of all, don't use 1 word seeds, that will be too easy to brute force...</p>

<p><strong>index.js</strong></p>

<pre><code>const bitcoin = require('bitcoinjs-lib')

const brainsrc = 'satoshi'
const hash = bitcoin.crypto.sha256(Buffer.from(brainsrc))
const keyPair = bitcoin.ECPair.fromPrivateKey(hash)
const addr = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey }).address
const secret = keyPair.toWIF()

console.log('The brain wallet of '+brainsrc+' \nAddress: '+addr,' Private key:'+secret)
</code></pre>

<p><strong>output:</strong></p>

<pre><code>$ node index.js
The brain wallet of satoshi
Address: 1xm4vFerV3pSgvBFkyzLgT1Ew3HQYrS1V  Private key:L4XnHhvLC1b4ag9L2PM9kRicQxUoYT1Q36PQ21YtLNkrAdWZNos6
</code></pre>

<p>Examples can be found on the git repo: <a href="https://github.com/bitcoinjs/bitcoinjs-lib#examples" rel="nofollow noreferrer">https://github.com/bitcoinjs/bitcoinjs-lib#examples</a></p>

CC BY-SA 4.0
2018-09-13T00:48:58.123Z
TypeError: bitcoin.ECPair.fromPrivateKey is not a function
TSR
CC BY-SA 4.0
2018-09-13T01:31:31.193Z
what version of `bitcoinjs-lib` and `node` are you using?
JBaczuk
CC BY-SA 4.0
2018-09-13T02:05:29.460Z
Yes node. I upgraded to  4.0.0 and it works.
TSR
CC BY-SA 4.0
2018-09-13T02:05:58.867Z
It would be a plus if you can provide a link to the documentation
TSR
CC BY-SA 4.0
2018-09-13T02:20:15.020Z
Good idea, just edited the answer, Bitcoinjs-lib doesn't have formal docs, but there are examples.
JBaczuk
CC BY-SA 4.0
2018-09-12T20:43:21.697Z
2018-09-13T02:19:36.350Z
2018-09-13T02:19:36.350Z
JBaczuk
<p>This is how to create a brainwallet with bitcore</p>

<pre><code>const Bitcore = require("bitcore-lib");
// const Mnemonic = require("bitcore-mnemonic");
// https://bitcore.io/api/lib/crypto
let brainsrc= 'satoshi'
let input = new Buffer(brainsrc)
let hash = Bitcore.crypto.Hash.sha256(input)
let bn = Bitcore.crypto.BN.fromBuffer(hash)
let pk = new Bitcore.PrivateKey(bn).toWIF()
let addy = new Bitcore.PrivateKey(bn).toAddress();
console.log('The brain wallet of '+brainsrc+' \nAddress: '+addy,' Private key:'+pk)
</code></pre>

<p>For bitcoinjs, I only know how to create random address:</p>

<pre><code>// https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js

const bitcoin = require('bitcoinjs-lib')
var keyPair = bitcoin.ECPair.makeRandom()
var secret = (keyPair.toWIF())
var addr = (keyPair.getAddress())

console.log('The brain wallet of '+brainsrc+' \nAddress: '+addr,' Private key:'+secret)
</code></pre>

<p>How to do it?</p>

<wallet><bitcoinjs><brain-wallet>
How to create a brainwallet with bitcoinjs?
TSR
# How to create a brainwallet with bitcoinjs?

(Asked by: username_0 on 2018-09-12)

This is how to create a brainwallet with bitcore

```
const Bitcore = require("bitcore-lib");
// const Mnemonic = require("bitcore-mnemonic");
// https://bitcore.io/api/lib/crypto
let brainsrc= 'satoshi'
let input = new Buffer(brainsrc)
let hash = Bitcore.crypto.Hash.sha256(input)
let bn = Bitcore.crypto.BN.fromBuffer(hash)
let pk = new Bitcore.PrivateKey(bn).toWIF()
let addy = new Bitcore.PrivateKey(bn).toAddress();
console.log('The brain wallet of '+brainsrc+' \nAddress: '+addy,' Private key:'+pk)

```

For bitcoinjs, I only know how to create random address:

```
// https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js

const bitcoin = require('bitcoinjs-lib')
var keyPair = bitcoin.ECPair.makeRandom()
var secret = (keyPair.toWIF())
var addr = (keyPair.getAddress())

console.log('The brain wallet of '+brainsrc+' \nAddress: '+addr,' Private key:'+secret)

```

How to do it?

**Tags:** wallet, bitcoinjs, brain-wallet


---

## 1 answers

### Answer by username_1 on 2018-09-12. Score: 0 | Accepted answer

First of all, don't use 1 word seeds, that will be too easy to brute force...

**index.js**

```
const bitcoin = require('bitcoinjs-lib')

const brainsrc = 'satoshi'
const hash = bitcoin.crypto.sha256(Buffer.from(brainsrc))
const keyPair = bitcoin.ECPair.fromPrivateKey(hash)
const addr = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey }).address
const secret = keyPair.toWIF()

console.log('The brain wallet of '+brainsrc+' \nAddress: '+addr,' Private key:'+secret)

```

**output:**

```
$ node index.js
The brain wallet of satoshi
Address: 1xm4vFerV3pSgvBFkyzLgT1Ew3HQYrS1V  Private key:L4XnHhvLC1b4ag9L2PM9kRicQxUoYT1Q36PQ21YtLNkrAdWZNos6

```

Examples can be found on the git repo: <https://github.com/bitcoinjs/bitcoinjs-lib#examples>

> **Comments:**
> **username_0**: TypeError: bitcoin.ECPair.fromPrivateKey is not a function  
> **username_1**: what version of `bitcoinjs-lib` and `node` are you using?  
> **username_0**: Yes node. I upgraded to  4.0.0 and it works.  
> **username_0**: It would be a plus if you can provide a link to the documentation  
> **username_1**: Good idea, just edited the answer, Bitcoinjs-lib doesn't have formal docs, but there are examples.  

---

