You can generate a bitcoin wallet in many different ways, using bitcoin core client or using online wallet services or getting it from hardware wallet manufacturers etc.

What does a bitcoin wallet contains ?

It contains two keys private key, public key and a public address. The private key is used for spending your coins(i.e. signing a transaction) whereas the public key is used in verifying a signed transaction.
As public key is long it is shortened to create a address in a way that it becomes more readable, concise and less error prone while transacting.
So, Address is what you publish in public to receive bitcoins.

Flow Diagram courtesy bitcoin wiki

How bitcoin wallet keys are generated ?


  1. Generate a random number of length 32 bytes which will be called your private key.(Random number must be truly random or should be generated from cryptographically strong pseudo random number generator)
  2. Apply ECDSA algorithm on private key derived from previous step to create a public key of length 65 bytes. 0x04 as prefix.

How bitcoin P2PKH address is derived from public key ?


  1. Public key is hashed with SHA256 algorithm.
  2. Hash derived from previous step is hashed again with RIPMED-160 algorithm.
  3. Then, add bytes 00 as prefix to the hash derived from previous step.
  4. Hash received from previous step is again hashed with SHA256 algorithm two times sequentially to take out first four bytes from result as checksum.
  5. Now these checksum bytes are added as suffix to output of step 3.
  6. Lastly we encode resultant bytes using Base58 notation to get a Bitcoin Address.

Javascript code to generate a Bitcoin P2PKH address

In a update to this blog, i'll we generating a bitcoin wallet using javascript.
stay tuned.

Next Blog post link :