Tutorial on Hierarchical Deterministic wallets in Nimiq

HD wallets with Nimiq

As I was experimenting with the Entropy and ExtendedPrivateKey classes in Nimiq core, I eventually came up with detailed overview how you could use them in your new application.

HD wallets are based on the BIP32 and BIP44 proposals for creating a fixed structure and deriving ‘infinite’ addresses based on a hierarchical and deterministic way.

Following those proposals gives rise to having one seed needed for all your addresses. And since it’s deterministic, you can easily derive all your addresses and funds with only that one seed. It removes the pain of storing every privatekey for every new address you generate. When you want to import all your addresses again, you only have import your given seed and all your corresponding addresses (including funds) will be detected and imported.

Note that at this time of writing, Nimiq only uses the first account derived from the seed: m/44'/242'/0' (called a path) and its corresponding addresses. I explain what a path is in the Github example.

Click here for my Github example.

7 Likes

Well done!

Keep in mind that we are only using the first account of a seed in our apps currently (m/44'/242'/0') and are calling the addresses generated from that ‘addresses’, and not ‘wallets’.

You can also mention in your code comments that the 44 signals that the wallet is derived following the BIP44 standard.

Thanks for the feedback. I updated the wallet/address terminology and added a note that Nimiq only uses the first account of the seed.

Great work. This saved me a lot of time and research :grinning:

1 Like