<p>It looks like you're trying to get a key from a seed, rather than deriving a key using a path. This uses the default derivation settings, which attempt to derive a hardened key, which can't be done using an extended public key.</p>

<p>Try an explicit, non-hardened derivation instead:</p>

<pre><code>val xpub = "xpub661MyMwAqRbcGiwzoCu93MuL6H91qANYUoYBwD4xSH8bRKJVNXsP1FUnNYiWUiu4trHbs3tavhbr4ih9bwNeVBmdQAnrA5SwSEVVCFza8dy"
val keyChainSeed : DeterministicKey =  DeterministicKey.deserializeB58(null,xpub, MainNetParams.get)
DeterministicKey key = HDKeyDerivation.deriveChildKey(
         keyChainSeed, new ChildNumber(0, false));
val w = Wallet.fromWatchingKey(MainNetParams.get, key);
</code></pre>

<p>P.S. You should read the <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki" rel="nofollow">BIP32 spec</a> if you haven't already.</p>

CC BY-SA 3.0
2015-05-15T21:59:18.830Z
This did not work, I'm still getting the same error.
Chris Stewart
CC BY-SA 3.0
2015-05-15T21:21:39.877Z
2015-05-15T21:21:39.877Z
Nick ODell
<p>I'm trying to create a <code>bitcoinj</code> determinstic key chain from a BIP32 master public key. This is the code that I have written so far: </p>

<pre><code>val xpub = "xpub661MyMwAqRbcGiwzoCu93MuL6H91qANYUoYBwD4xSH8bRKJVNXsP1FUnNYiWUiu4trHbs3tavhbr4ih9bwNeVBmdQAnrA5SwSEVVCFza8dy"
val keyChainSeed : DeterministicKey =  DeterministicKey.deserializeB58(null,xpub, MainNetParams.get)
val w = Wallet.fromWatchingKey(MainNetParams.get, keyChainSeed)
</code></pre>

<p>but I get the following error: </p>

<pre><code>No key found for absolute path M/0H.
java.lang.IllegalArgumentException: No key found for absolute path M/0H.
    at org.bitcoinj.crypto.DeterministicHierarchy.get(DeterministicHierarchy.java:94)
    at org.bitcoinj.crypto.DeterministicHierarchy.deriveChild(DeterministicHierarchy.java:152)
    at org.bitcoinj.wallet.DeterministicKeyChain.initializeHierarchyUnencrypted(DeterministicKeyChain.java:590)
    at org.bitcoinj.wallet.DeterministicKeyChain.&lt;init&gt;(DeterministicKeyChain.java:384)
    at org.bitcoinj.wallet.DeterministicKeyChain.&lt;init&gt;(DeterministicKeyChain.java:393)
    at org.bitcoinj.wallet.DeterministicKeyChain.watch(DeterministicKeyChain.java:444)
    at org.bitcoinj.wallet.DeterministicKeyChain.watch(DeterministicKeyChain.java:436)
    at org.bitcoinj.wallet.KeyChainGroup.&lt;init&gt;(KeyChainGroup.java:115)
    at org.bitcoinj.core.Wallet.fromWatchingKey(Wallet.java:260)
    at com.suredbits.core.bitcoin.WalletTest$$anonfun$2.apply$mcV$sp(WalletTest.scala:84)
    at com.suredbits.core.bitcoin.WalletTest$$anonfun$2.apply(WalletTest.scala:80)
    at com.suredbits.core.bitcoin.WalletTest$$anonfun$2.apply(WalletTest.scala:80)
</code></pre>

<p>I'm not sure why this isn't working, as <code>bitcoinj</code> supports BIP32. Can anyone spot what I am doing incorrectly?</p>

<bitcoinj><bip32-hd-wallets>
Creating a Deterministic Keychain from BIP32 master public key
Chris Stewart
# Creating a Deterministic Keychain from BIP32 master public key

(Asked by: username_0 on 2015-05-15)

I'm trying to create a bitcoinj determinstic key chain from a BIP32 master public key. This is the code that I have written so far: 
val xpub = "xpub661MyMwAqRbcGiwzoCu93MuL6H91qANYUoYBwD4xSH8bRKJVNXsP1FUnNYiWUiu4trHbs3tavhbr4ih9bwNeVBmdQAnrA5SwSEVVCFza8dy"
val keyChainSeed : DeterministicKey =  DeterministicKey.deserializeB58(null,xpub, MainNetParams.get)
val w = Wallet.fromWatchingKey(MainNetParams.get, keyChainSeed)

but I get the following error: 
No key found for absolute path M/0H.
java.lang.IllegalArgumentException: No key found for absolute path M/0H.
    at org.bitcoinj.crypto.DeterministicHierarchy.get(DeterministicHierarchy.java:94)
    at org.bitcoinj.crypto.DeterministicHierarchy.deriveChild(DeterministicHierarchy.java:152)
    at org.bitcoinj.wallet.DeterministicKeyChain.initializeHierarchyUnencrypted(DeterministicKeyChain.java:590)
    at org.bitcoinj.wallet.DeterministicKeyChain.(DeterministicKeyChain.java:384)
    at org.bitcoinj.wallet.DeterministicKeyChain.(DeterministicKeyChain.java:393)
    at org.bitcoinj.wallet.DeterministicKeyChain.watch(DeterministicKeyChain.java:444)
    at org.bitcoinj.wallet.DeterministicKeyChain.watch(DeterministicKeyChain.java:436)
    at org.bitcoinj.wallet.KeyChainGroup.(KeyChainGroup.java:115)
    at org.bitcoinj.core.Wallet.fromWatchingKey(Wallet.java:260)
    at com.suredbits.core.bitcoin.WalletTest$$anonfun$2.apply$mcV$sp(WalletTest.scala:84)
    at com.suredbits.core.bitcoin.WalletTest$$anonfun$2.apply(WalletTest.scala:80)
    at com.suredbits.core.bitcoin.WalletTest$$anonfun$2.apply(WalletTest.scala:80)

I'm not sure why this isn't working, as bitcoinj supports BIP32. Can anyone spot what I am doing incorrectly?

**Tags:** bitcoinj, bip32-hd-wallets


---

## 1 answers

### Answer by username_1 on 2015-05-15. Score: 1

It looks like you're trying to get a key from a seed, rather than deriving a key using a path. This uses the default derivation settings, which attempt to derive a hardened key, which can't be done using an extended public key.
Try an explicit, non-hardened derivation instead:
val xpub = "xpub661MyMwAqRbcGiwzoCu93MuL6H91qANYUoYBwD4xSH8bRKJVNXsP1FUnNYiWUiu4trHbs3tavhbr4ih9bwNeVBmdQAnrA5SwSEVVCFza8dy"
val keyChainSeed : DeterministicKey =  DeterministicKey.deserializeB58(null,xpub, MainNetParams.get)
DeterministicKey key = HDKeyDerivation.deriveChildKey(
         keyChainSeed, new ChildNumber(0, false));
val w = Wallet.fromWatchingKey(MainNetParams.get, key);

P.S. You should read the BIP32 spec if you haven't already.

> **Comments:**
> **username_0**: This did not work, I'm still getting the same error.  

---

