Deriving wallet all addresses as once using bitcoinj

311 views
Skip to first unread message

Tyga

unread,
May 16, 2018, 4:33:21 PM5/16/18
to bitcoinj
can i derive all wallet addresses using bitcoinj just like this site https://iancoleman.io/bip39/
this site generates list of addresses along with address path pub key and prv key.
is bitcoinj support this, if yes then little code example will be helpfull.

Andreas Schildbach

unread,
May 16, 2018, 5:54:38 PM5/16/18
to bitc...@googlegroups.com
After synching the wallet using the blockchain, all addresses are known
to the wallet. I suggest looking at Wallet.toString() and its call
hierarchy to learn how you could enumerate all wallet addresses.



Jose Luis Estevez

unread,
May 17, 2018, 2:56:55 AM5/17/18
to bitcoinj

I have done something similar to what you want


Copy yours nnemonic seed 15 words, in the input BIP39 Mnemonic like "brisk wood symptom party betray ozone dad super beyond sea memory power pig business extra"
In Coin Select BTC
In Derivation Path select the Tab BIP32
In Client select MultiBitHD

Java example


String mnemonic = "brisk wood symptom party betray ozone dad super beyond sea memory power pig business extra";
DeterministicSeed seed = new DeterministicSeed(mnemonic, null, "", new Date().getTime());
Wallet wallet = Wallet.fromSeed(params, seed);
System.out.println(wallet);
DeterministicKeyChain keyChain = DeterministicKeyChain.builder().seed(seed).build();


 
// Derive 100 children
keyChain
.maybeLookAhead();


// Get M/0H/0/5 key
DeterministicKey key5 = keyChain.getKeyByPath(ImmutableList.of(ChildNumber.ZERO_HARDENED, ChildNumber.ZERO, new ChildNumber(5)), false);


System.out.println(key5.toAddress(params).toString());

Tyga

unread,
May 17, 2018, 12:59:30 PM5/17/18
to bitcoinj
Thanks

Tyga

unread,
May 18, 2018, 5:04:30 AM5/18/18
to bitcoinj
i am using this to drive addresses along with wallet path

int i = 0;
while (i < 1000)
{
   
System.out.println(wallet.freshReceiveKey());
   
System.out.println(wallet.freshReceiveAddress());
    i
++;
}
//Output

DeterministicKey{pub=0366b8dbd08729c30e89b7ded964340cef1fdc242c87b78f263368fa49370c5fc3, chainCode=daec01ad1433036495c481e59d454c426889535b918931d33146527259a75fa9, path=M/0H/0/0, isEncrypted=false, isPubKeyOnly=false}
mwKwy5bW2wsgnbMAVffnAjY3b6MkZRHSDq

//and so on
//after running this loop 2 or 3 times it start printing only odd or even number of wallet path  like this

DeterministicKey{pub=0366b8dbd08729c30e89b7ded964340cef1fdc242c87b78f263368fa49370c5fc3, chainCode=daec01ad1433036495c481e59d454c426889535b918931d33146527259a75fa9, path=M/0H/0/0, isEncrypted=false, isPubKeyOnly=false}
mwKwy5bW2wsgnbMAVffnAjY3b6MkZRHSDq
DeterministicKey{pub=023308963dff0ab887a401a57d48be1330da4017d27e0b442380195f5cd4e8a412, chainCode=8b414a715c0fb792f50ba22fcbd1285e4a5ade41609c72663dfe6bdfe6664e1a, path=M/0H/0/2, isEncrypted=false, isPubKeyOnly=false}
mjM8Fx6gntMUGULTrQGMXZDoreBvv7q4Ge
DeterministicKey{pub=02750837c37eaebf071152376e24efe8c09f00b595026b052e9627db4bdbfcb0a3, chainCode=0b888586c9bde0a2a753ba0795fb1b8b73241cc331e4d04c7da3faf92afda315, path=M/0H/0/4, isEncrypted=false, isPubKeyOnly=false}
mzbMquG2ksco6YNpat83ugg2ChSefuTA3t
DeterministicKey{pub=0261be11f3a024b57d2dc1c37867487485f3369c836e2409aeaaab8f8669ea95aa, chainCode=bfad423c4fa8e0401a69c3fae835f941260d16454c75860298e7d28abb25d69f, path=M/0H/0/6, isEncrypted=false, isPubKeyOnly=false}
mkD1sJxQx2JSB12mwo71njArASLmYXBGfp



why is this happening ? also my wallet is offline can't link with blockchian

Another question is @Jose Luis Estevez when i run your code snippet i can only drive addresses upto 125 why ?
and also why the path address is differ like
moL4SbJFQnRBwtabB3GDdB73BZmWM3cPFD
M
/0H/0/10
// this is the address of path that i am printing using your code
// and


DeterministicKey{pub=0366b8dbd08729c30e89b7ded964340cef1fdc242c87b78f263368fa49370c5fc3, chainCode=daec01ad1433036495c481e59d454c426889535b918931d33146527259a75fa9, path=M/0H/0/0, isEncrypted=false, isPubKeyOnly=false}
mwKwy5bW2wsgnbMAVffnAjY3b6MkZRHSDq


//this is the address that i am printing using above code snippet



why the both addresses are different while the path of both are same ?

Jose Luis Estevez

unread,
May 18, 2018, 6:18:51 AM5/18/18
to bitcoinj
Check it

 The default lookahead zone is 100 keys, meaning if  the user hands out more than 100 addresses and receives payment on them before the chain is next scanned, some  transactions might be missed. 100 is a reasonable choice for consumer wallets running on CPU constrained devices.



To get more than 100 I think you should modify this value



Java Example



El miércoles, 16 de mayo de 2018, 22:33:21 (UTC+2), Tyga escribió:

Andreas Schildbach

unread,
May 19, 2018, 4:29:15 AM5/19/18
to bitc...@googlegroups.com
On 05/18/2018 11:04 AM, Tyga wrote:
> i am using this to drive addresses along with wallet path
>
> int i = 0;
> while (i < 1000)
> {
> System.out.println(wallet.freshReceiveKey());
> System.out.println(wallet.freshReceiveAddress());
> i++;
> }
> //Output
>
> DeterministicKey{pub=
> 0366b8dbd08729c30e89b7ded964340cef1fdc242c87b78f263368fa49370c5fc3,
> chainCode=daec01ad1433036495c481e59d454c426889535b918931d33146527259a75fa9,
> path=M/0H/0/0, isEncrypted=false, isPubKeyOnly=false}
> mwKwy5bW2wsgnbMAVffnAjY3b6MkZRHSDq
>
> //and so on
> //after running this loop 2 or 3 times it start printing only odd or even
> number of wallet path like this

freshReceiveAddress() also calls freshReceiveKey() (and then derives an
address from it). The addresses printed between the keys are the odd
indexes in your case.

> DeterministicKey{pub=
Reply all
Reply to author
Forward
0 new messages