How to use bitcoin address

How to Generate a Bitcoin Address — Step by Step

Here is a bash script that does what is outlined below: https://bit.ly/2MIgeOD

Introduction

This is a hands-on, technical guide about the generation of Bitcoin addresses including private and public keys, and the cryptography involved.

Learn more and join people in 22 countries around the world in my course on how to Become a Bitcoin + Blockchain Programmer.

This guide will walk you through all the steps to generate a Bitcoin address using the command line on a Mac. Similar steps should be possible on other operating systems using similar cryptographic tools. Lines starting with $ denote terminal commands, which you can type and run (without the $ of course).

Dependencies

  • brew — Installation: https://brew.sh/
  • pip — Installation: sudo easy_install pip
  • libressl — Installation: brew install libressl
  • base58 — Installation: pip install base58

Note: To do the contained openssl cli commands, I installed libressl in order for some of the elliptic curve commands to work as the current version of openssl cli on mac has a bug.

Cryptography Primer

Public Key Cryptography

Or asymmetric cryptography, is a type of cryptography that uses key pairs, each of which is unique. The pair of keys includes a public key and a private key. This is the type of cryptography that Bitcoin uses to control funds. A public key can be generated from a private key, but not vice-versa (computationally too difficult). Also, something encrypted with a private key can be decrypted with the public key, and vice-versa, hence they are asymmetric.

  • Encryption: When a user has a public key, a message can be encrypted using a public key, which can only be read by the person with the private key. This also works in reverse.
  • Digital Signatures: A user can, with their private key and a hash of some data, use a digital signature algorithm such as ECDSA, to calculate a digital signature. Then, another user can use the algorithm to verify that signature using the public key and the hash of the same data. If it passes, this proves a user did in fact submit a specific message, which has not been tampered with.
  • Digital Fingerprint: Is a way to represent an arbitrarily large data set by computing the hash of it to generate a fingerprint of a standard size. This fingerprint would be so difficult to replicate without the same exact data, which can be assumed to have not been tampered with.

Private keys are what prove you can send Bitcoin that has been sent to you. It is like the password to your bank account. If you lose it or someone else gets a hold of it, you’re toast.

Public keys help people know how to send you Bitcoin.

Creating a Bitcoin Address

Private Key Generation

Private keys can be any 256 bit (32 byte) value from 0x1 to 0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF BAAE DCE6 AF48 A03B BFD2 5E8C D036 4140 .¹

The total possible number of private keys is therefore 2²⁵⁶ or 1.16 x 10⁷⁷. Imagine the total number of atoms in your body, then imagine that each of those atoms is an earth. The total number of atoms on all of those earths is about 7 x 10⁷⁷.² There is virtually no chance that your random private key will ever be generated randomly or found by someone else.

A common (but not the most secure) way of creating a private key is to start with a seed, such as a group of words or passphrases picked at random. This seed is then passed through the SHA256 algorithm, which will always conveniently generate a 256 bit value. This is possible because every computer character is represented by an integer value (see ASCII and Unicode).

Note: SHA256 is a one-way, deterministic function meaning that it is easy to compute in one direction, but you cannot reverse it. In order to find a specific output, you have to try all the possible inputs until you get the desired output (brute forcing) and it will always produce the same output given the same input, respectively.

The seed can be used to generate the same private key if the same hashing algorithm is used in the future, so it is only necessary to save the seed.

Читайте также:  По фишеру инвестиции это

This private key is in hexadecimal or base 16. Every 2 digits represents 8 bits or 1 byte. So, with 64 characters, there are 256 bits total.

Public Key Generation

Public keys are generated from the private keys in Bitcoin using elliptic curve ( secp256k1 ) multiplication using the formula K = k * G , where K is the public key, k is the private key, and G is a constant called the Generator Point⁴, which for secp256k1 is equal to:

It doesn’t seem to be known how this point was chosen by they designers of the curve. Also, this algorithm is a one-way algorithm, or a “trap door” function so that a private key cannot be derived from the public key. It is important to note that elliptic curve multiplication is not the same as scalar multiplication, though it does share similar properties.

To do this in the terminal from our private key earlier,

This public key contains a prefix 0x04 and the x and y coordinates on the elliptic curve secp256k1 , respectively.

Compressed Public Key

Most wallets and nodes implement compressed public key as a default format because it is half as big as an uncompressed key, saving blockchain space. To convert from an uncompressed public key to a compressed public key, you can omit the y value because the y value can be solved for using the equation of the elliptic curve: y² = x³ + 7. Since the equation solves for y², the right side of the equation could be either positive or negative. So, 0x02 is prepended for positive y values, and 0x03 is prepended for negative ones. If the last binary digit of the y coordinate is 0, then the number is even, which corresponds to positive. If it is 1, then it is negative. The compressed version of the public key becomes:

The prefix is 0x02 because the y coordinate ends in 0xa4 , which is even, therefore positive.

Address Generation

There are multiple Bitcoin address types, currently P2SH or pay-to-script hash is the default for most wallets. P2PKH was the predecessor and stands for Pay to Public Key Hash. Scripts give you more functionality, which is one reason why they are more popular. We’ll first generate a P2PKH original format address, followed by the now standard P2SH .

The public key from the previous output is hashed first using sha256 and then hashed using ripemd160 . This shortens the number of output bytes and ensures that in case there is some unforeseen relationship between elliptic curve and sha256, another unrelated hash function would significantly increase the difficulty of reversing the operation:

Note that since the input is a string, the xxd -r -p will convert the hex string into binary and then output it in hexdump style (ascii), which is what the openssl hashing functions expect as input.

Now that we have hashed the public key, we now perform base58check encoding. Base58check allows the hash to be displayed in a more compact way (using more letters of the alphabet) while avoiding characters that could be confused with each other such as 0 and O where a typo could result in your losing your funds. A checksum is applied to make sure the address was transmitted correctly without any data corruption such as mistyping the address.

Читайте также:  Что такое инн инвестиции

Bitcoin P2PKH addresses begin with the version byte value 0x00 denoting the address type and end with a 4 byte checksum. First we prepend the version byte (prefix) to our public key hash and calculate and append the checksum before we encode it using base58 :

Note: -c denotes a checksum is to be applied. The checksum is calculated as checksum = SHA256(SHA256(prefix+data)) and only the first 4 bytes of the hash are appended to the end of the data.

The resulting value is a P2PKH address that can be used to receive Bitcoin: 16JrGhLx5bcBSA34kew9V6Mufa4aXhFe9X

Pay-to-Script Hash

The new default address type is a pay-to-script-hash, where instead of paying to a pubKey hash, it is a script hash. Bitcoin has a scripting language, you can read more about it here. Basically it allows for things like multiple signature requirements to send Bitcoin or a time delay before you are allowed to send funds, etc. A commonly used script is a P2WPKH (Pay to Witness Public Key Hash): OP_0 0x14

where the PubKey Hash is the RIPEMD160 of the SHA256 of the public key, as before, and 0x14 is the number of bytes in the PubKey Hash. So, to turn this script into an address, you simply apply BASE58CHECK to the RIPEMD160 of the SHA256 of the script OP_0 0x14

except you prepend 0x05 to the script hash instead of 0x00 to denote the address type is a P2SH address.

If you like the article, check out my course on how to Become a Bitcoin + Blockchain Programmer.

Источник

How To Get A Bitcoin Address & Why It Is Important

(Note: This article is for Bitcoin beginners.)

We all know how Bitcoin is taking over the world. But the funny part is people still fail to understand what it is and why it has become such a revolution.

Here are some of the facts we lined up – 9 Interesting Bitcoin Facts Every Bitcoin Owner Should Know – but there are more.

Bitcoin is a fully functional digital currency through which any amount of value can be transferred anytime anywhere in the world and there is nothing one can do to stop it.

Also, it a finite commodity to hold and as rare as explained by this tweet:

If you get 0.1 BTC no more than 2% of the world’s population can own more BTC than you. Once this dawns on enough people there will be a stampede to try to get even 0.1.

Despite this, many remain clueless about this revolutionary internet money and the first thing they ask is How do I get Bitcoin? Or How do I get a Bitcoin address?

Well, that’s what I am here to tell you and also to share some points so that you don’t get scammed.

How To Get A Bitcoin Address

A valid Bitcoin address is like a bank account number using which you store your bitcoins and check your balances.

For those who are seeing their Bitcoin addresses for the first time, I would say that it won’t look like traditional bank account number but instead, it looks like a long alphanumeric string starting usually with ‘1’ or ‘3”.

And for those who haven’t seen a Bitcoin address and think of it as an email address, you’re wrong!

Читайте также:  Bitcoin litecoin ethereum wallet

Different Bitcoin addresses:

There are currently three address formats in use:

  1. P2PKH which begins with the number 1, for e.g.: 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2.
  2. P2SH type starting with the number 3, for e.g.: 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy.
  3. Bech32 type starting with bc1, for e.g.: bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq.

Now, that you have understood the types, format and what a BTC address looks like, it makes sense in talking about some of the reliable sources from where you can get your Bitcoin address if you haven’t already.

These sources are categorized based on device type & usage:

Mobile Bitcoin Wallets

Hardware devices that act like Bitcoin wallets also generate valid Bitcoin addresses. This is a physical device like a small USB and something you should use if you planning to hold Bitcoins for a longer period. This is also useful for those who wish to have a permanent Bitcoin wallet address.

Here are two most popular Bitcoin hardware wallets:

Watch this video tutorial to understand more about how to set-up your hardware wallet like Ledger Nano S to get your Bitcoin address.

For desktop lovers, there are desktop wallets that generate valid Bitcoin addresses. Some of these desktop wallets are:

Why Is Bitcoin Address Important?

A valid Bitcoin address is necessary because if you get this wrong, your bitcoins will be lost.

If you send bitcoins to an invalid address, the bitcoins will be lost in cyberspace or will remain with the sender.

Another way in which you can get scammed is when you are using a paper wallet-based Bitcoin address that you have received from someone. In this case, let’s assume the person who has given you this Bitcoin address is an attacker and he has already kept a copy of the private keys associated with that address.

And now you haven’t done a sweep of your paper wallet and are using the same address to receive your bitcoins. In this case, the attacker can take away all your coins once you have received coins on the address because he has a copy of the paper wallet private keys which are still valid because you haven’t swept.

Plus, if you are into the online business, it is good to be in tandem with the modern changing society which is internet driven and have the BTC addresses to receive payments.

Lastly, through a BTC address, you can actually make millions and billions of dollars with you across borders, something which was not possible before the invention of Bitcoin. You can sum up all your worth in bitcoins and get settled in another country altogether with the help of a Bitcoin address.

I’m sure you now know how you can get a Bitcoin address and why it is important to have one for yourself.

Now you tell us: Are you into Bitcoins yet, or are you still thinking? Do you have a Bitcoin address? Do share with us in the comment section below.

If you find this post useful, do share it with your friends on Facebook & Twitter!

Harsh Agrawal is the Crypto exchange and bots expert for CoinSutra. He founded CoinSutra in 2016, and one of the industry’s most regarded professional blogger in the fin-tech space.

An award-winning blogger with a track record of 10+ years. He has a background in both finance and technology and holds professional qualifications in Information technology.

An international speaker and author who loves blockchain and crypto world.

After discovering about decentralized finance and with his background of Information technology, he made his mission to help others learn and get started with it via CoinSutra.

Join us via email and social channels to get the latest updates straight to your inbox.

Источник

Оцените статью