Mastering bitcoin book pdf download 1st edition






















Anyone with a basic understanding of technology can read the first two chapters to get a great understanding of bitcoin. This repository contains the complete first edition, second print , published in December , and the complete second edition, third print , published in March , as published by O'Reilly Media in paperback and ebook formats.

If you know how to make a pull request to contribute a fix, please write the correction and use a pull request to submit it for consideration against the develop branch. If you are making several changes, please use a separate commit for each to make it easier to cherry-pick or resolve conflicts. Otherwise, please submit an issue, explaining the error or comment.

To read this book, see book. Click on each of the chapters to read in your browser. The algorithm for Proof-of-Work involves repeatedly hashing the header of the block and a random number with the SHA cryptographic algorithm until a solution matching a predetermined pattern emerges.

The first miner to find such a solution wins the round of competition and publishes that block into the blockchain. Jing started mining in using a very fast desktop computer to find a suitable Proof-of-Work for new blocks.

As more miners started joining the bitcoin network, the difficulty of the problem increased rapidly. Soon, Jing and other miners upgraded to more specialized hardware, such as high-end dedicated graphical processing units GPUs cards such as those used in gaming desktops or consoles.

At the time of this writing, the difficulty is so high that it is profitable only to mine with application-specific integrated circuits ASIC , essentially hundreds of mining algorithms printed in hardware, running in parallel on a single silicon chip. The company pays its electricity costs by selling the bitcoin it is able to generate from mining, creating some income from the profits.

Mining Transactions in Blocks New transactions are constantly flowing into the network from user wallets and other applications. As these are seen by the bitcoin network nodes, they get added to a temporary pool of unverified transactions maintained by each node. As miners construct a new block, they add unverified transactions from this pool to the new block and then attempt to prove the validity of that new block, with the mining algorithm Proof-of-Work.

The process of mining is explained in detail in Chapter Transactions are added to the new block, prioritized by the highest-fee transactions first and a few other criteria. Each miner starts the process of mining a new block of transactions as soon as he receives the previous block from the network, knowing he has lost that previous round of competition.

He immediately creates a new block, fills it with transactions and the fingerprint of the previous block, and starts calculating the Proof-of-Work for the new block.

Each miner includes a special transaction in his block, one that pays his own bitcoin address the block reward currently Jing, who participates in a mining pool, has set up his software to create new blocks that assign the reward to a pool address. From there, a share of the reward is distributed to Jing and other miners in proportion to the amount of work they contributed in the last round. All the miners participating in that mining pool immediately start computing Proof-of-Work for the candidate block.

Once other miners validated the winning block they started the race to generate the next block. Approximately 19 minutes later, a new block, , is mined by another miner. As the blocks pile on top of each other, it becomes exponentially harder to reverse the transaction, thereby making it more and more trusted by the network.

Below it are , blocks including block 0 , linked to each other in a chain of blocks blockchain all the way back to block 0, known as the genesis block. By convention, any block with more than six confirmations is considered irrevocable, because it would require an immense amount of computation to invalidate and recalculate six blocks. We will examine the process of mining and the way it builds trust in more detail in Chapter Each bitcoin client can independently verify the transaction as valid and spendable.

Bob can now spend the output from this and other transactions. This would aggregate the various payments into a single output and a single address. For a diagram of an aggregating transaction, see Figure As Bob spends the payments received from Alice and other customers, he extends the chain of transactions. Now the chain of transactions will look like Figure In the rest of this book we will examine the specific technologies behind wallets, addresses, signatures, transactions, the network, and finally mining.

Chapter 3. Bitcoin Core: The Reference Implementation Bitcoin is an open source project and the source code is available under an open MIT license, free to download and use for any purpose.

Open source means more than simply free to use. It also means that bitcoin is developed by an open community of volunteers. At first, that community consisted of only Satoshi Nakamoto.

Anyone can contribute to the code—including you! When bitcoin was created by Satoshi Nakamoto, the software was actually completed before the whitepaper reproduced in Appendix A was written. Satoshi wanted to make sure it worked before writing about it. It has evolved into what is known as Bitcoin Core, to differentiate it from other compatible implementations.

Bitcoin Core is the reference implementation of the bitcoin system, meaning that it is the authoritative reference on how each part of the technology should be implemented. Bitcoin Core implements all aspects of bitcoin, including wallets, a transaction and block validation engine, and a full network node in the peer-to-peer bitcoin network. Figure shows the architecture of Bitcoin Core.

Alternatively, use the git command line to create a local copy of the source code on your system. The shell will display a prompt; you type a command; and the shell responds with some text and a new prompt for your next command. Checking connectivity You may need to install the git command, or a graphical user interface for git, on your operating system if you do not have it already. When the git cloning operation has completed, you will have a complete local copy of the source code repository in the directory bitcoin.

Before compiling the code, select a specific version by checking out a release tag. This will synchronize the local copy with a specific snapshot of the code repository identified by a keyword tag.

Tags are used by the developers to mark specific releases of the code by version number. The list of tags shows all the released versions of bitcoin. From the preceding list, select the highest version release, which at the time of writing was v0. In this chapter, we will build the command-line bitcoin client, also known as bitcoind on Linux.

Alternative instructions for macOS and Windows can be found in the doc directory, as build-osx. Carefully review the build prerequisites, which are in the first part of the build documentation.

These are libraries that must be present on your system before you can begin to compile bitcoin. If these prerequisites are missing, the build process will fail with an error. If this happens because you missed a prerequisite, you can install it and then resume the build process from where you left off. Assuming the prerequisites are installed, you start the build process by generating a set of build scripts using the autogen.

Older versions use a simple Makefile and work slightly differently from the following example. Follow the instructions for the version you want to compile. The autogen. The most important of these is the configure script that offers a number of different options to customize the build process. In this chapter, we will build the bitcoind client with all the default features.

If you are in an academic setting, computer lab restrictions may require you to install applications in your home directory e. This builds server and command-line bitcoin only. If there are any missing libraries or errors, the configure command will terminate with an error instead of creating the build scripts. If an error occurs, it is most likely because of a missing or incompatible library.

Review the build documentation again and make sure you install the missing prerequisites. Then run configure again and see if that fixes the error. Building the Bitcoin Core Executables Next, you will compile the source code, a process that can take up to an hour to complete, depending on the speed of your CPU and available memory.

During the compilation process you should see output every few seconds or every few minutes, or an error if something goes wrong. If an error occurs, or the compilation process is interrupted, it can be resumed any time by typing make again.

Those running bitcoin nodes have a direct and authoritative view of the bitcoin blockchain, with a local copy of all the transactions, independently validated by their own system. Moreover, by running a bitcoin node you contribute to the bitcoin network by making it more robust. Running a node, however, requires a permanently connected system with enough resources to process all bitcoin transactions. Depending on whether you choose to index all transactions and keep a full copy of the blockchain, you may also need a lot of disk space and RAM.

Bitcoin nodes also transmit and receive bitcoin transactions and blocks, consuming internet bandwidth. If your internet connection is limited, has a low data cap, or is metered charged by the gigabit , you should probably not run a bitcoin node on it, or run it in a way that constrains its bandwidth see Example TIP Bitcoin Core keeps a full copy of the blockchain by default, with every transaction that has ever occurred on the bitcoin network since its inception in This dataset is dozens of gigabytes in size and is downloaded incrementally over several days or weeks, depending on the speed of your CPU and internet connection.

Bitcoin Core will not be able to process transactions or update account balances until the full blockchain dataset is downloaded. Make sure you have enough disk space, bandwidth, and time to complete the initial synchronization.

You can configure Bitcoin Core to reduce the size of the blockchain by discarding old blocks see Example , but it will still download the entire dataset before discarding data. Despite these resource requirements, thousands of volunteers run bitcoin nodes. Many volunteers also run bitcoin nodes on rented servers, usually some variant of Linux.

Why would you want to run a node? Here are some of the most common reasons: If you are developing bitcoin software and need to rely on a bitcoin node for programmable API access to the network and blockchain.

Typically, bitcoin software companies run several nodes. If you want to support bitcoin. Running a node makes the network more robust and able to serve more wallets, more users, and more transactions. If you do not want to rely on any third party to process or validate your transactions. If the file does not exist, create it with owner-readable-only file permissions. Additionally, it is recommended that you set up the alerting mechanism. In the next section we will examine the various configuration options and set up a configuration file.

Configuring the Bitcoin Core Node Edit the configuration file in your preferred editor and set the parameters, replacing the password with a strong password as recommended by bitcoind. Do not use the password shown in the book. To see a listing of these options, run bitcoind --help: bitcoind --help Bitcoin Core Daemon version v0. By default this is the. Make sure this filesystem has several gigabytes of free space. This means a complete copy of the blockchain that allows you to programmatically retrieve any transaction by ID.

Reducing this from the default will reduce your bandwidth consumption. Use if you have a data cap or pay by the gigabyte. Use it to reduce memory use of the node. Use on memory-constrained nodes. Below this value, the transaction is treated as zero fee. Use this on memory-constrained nodes to reduce the size of the in-memory transaction pool. Example shows how you might combine the preceding options, with a fully indexed node, running as an API backend for a bitcoin application.

To run Bitcoin Core in the background as a process, start it with the daemon option, as bitcoind - daemon. Once you are happy with the configuration options you have selected, you should add bitcoin to the startup scripts in your operating system, so that it runs continuously and restarts when the operating system restarts. The command line allows us to experiment interactively with the capabilities that are also available programmatically via the API.

To get additional help, a detailed description, and information on the parameters, add the command name after help. Arguments: 1. These examples demonstrate how you might call the command. But for now, this command should return the same result on your system, demonstrating that your Bitcoin Core node is running, is accepting commands, and has information about block to return to you. In the next sections we will demonstrate some very useful RPC commands and their expected output.

Among this data we see the version numbers for the bitcoin software client and bitcoin protocol We see the current block height, showing us how many blocks are known to this client We also see various statistics about the bitcoin network and the settings related to this client. You can check its progress using getinfo to see the number of known blocks.

Her transaction was recorded on the blockchain with transaction ID txid b6ffaeaf2ce4da4caa5a5fbd8acc2f2. Absence of a transaction hash in the blockchain does not mean the transaction was not processed. After confirmation, the txid is immutable and authoritative. The command getrawtransaction returns a serialized transaction in hexadecimal notation.

To decode that, we use the decoderawtransaction command, passing the hex data as a parameter. In this case we see that the transaction that credited our new address with 50 millibits used one input and generated two outputs. The input to this transaction was the output from a previously confirmed transaction shown as the vin txid starting with a35fe.

The two outputs correspond to the 50 millibit credit and an output with change back to the sender. We can further explore the blockchain by examining the previous transaction referenced by its txid in this transaction using the same commands e. Jumping from transaction to transaction we can follow a chain of transactions back as the coins are transmitted from owner address to owner address. However, blocks can be referenced either by the block height or by the block hash.

The height entry tells us this is the th block in the blockchain. But the whole point of an application programming interface is to access functions programmatically. In this section we will demonstrate accessing Bitcoin Core from another program. JSON stands for JavaScript Object Notation and it is a very convenient way to present data that both humans and programs can easily read. RPC stands for Remote Procedure Call, which means that we are calling procedures functions that are remote on the Bitcoin Core node via a network protocol.

We will use the python-bitcoinlib library to simplify API access. The Python script in Example makes a simple getinfo call and prints the block parameter from the data returned by Bitcoin Core. For each output, we show the recipient address and value. Retrieving a transaction and iterating its outputs from bitcoin. The next example, however, requires several hundred RPC calls and more clearly demonstrates the use of a programmatic interface.

In Example , we first retrieve block , then retrieve each of the transactions within by reference to each transaction ID. Retrieving a block and adding all the transaction outputs from bitcoin. Compare that to the amount reported by a block explorer site by searching for the block hash or height.

Some block explorers report the total value excluding the reward and excluding the fees. See if you can spot the difference. Alternative Clients, Libraries, and Toolkits There are many alternative clients, libraries, toolkits, and even full-node implementations in the bitcoin ecosystem.

These are implemented in a variety of programming languages, offering programmers native interfaces in their preferred language. The following sections list some of the best libraries, clients, and toolkits, organized by programming languages. Chapter 4. Keys, Addresses You may have heard that bitcoin is based on cryptography, which is a branch of mathematics used extensively in computer security.

Cryptography can also be used to prove knowledge of a secret without revealing that secret digital signature , or prove the authenticity of data digital fingerprint. These types of cryptographic proofs are the mathematical tools critical to bitcoin and used extensively in bitcoin applications.

Ironically, encryption is not an important part of bitcoin, as its communications and transaction data are not encrypted and do not need to be encrypted to protect the funds. In this chapter we will introduce some of the cryptography used in bitcoin to control ownership of funds, in the form of keys, addresses, and wallets.

Introduction Ownership of bitcoin is established through digital keys, bitcoin addresses, and digital signatures. The digital keys are not actually stored in the network, but are instead created and stored by users in a file, or simple database, called a wallet. Keys enable many of the interesting properties of bitcoin, including decentralized trust and control, ownership attestation, and the cryptographic-proof security model.

Most bitcoin transactions requires a valid digital signature to be included in the blockchain, which can only be generated with a secret key; therefore, anyone with a copy of that key has control of the bitcoin. The digital signature used to spend funds is also referred to as a witness, a term used in cryptography.

The witness data in a bitcoin transaction testifies to the true ownership of the funds being spent. Keys come in pairs consisting of a private secret key and a public key. Think of the public key as similar to a bank account number and the private key as similar to the secret PIN, or signature on a check, that provides control over the account.

These digital keys are very rarely seen by the users of bitcoin. For the most part, they are stored inside the wallet file and managed by the bitcoin wallet software. In most cases, a bitcoin address is generated from and corresponds to a public key. However, not all bitcoin addresses represent public keys; they can also represent other beneficiaries such as scripts, as we will see later in this chapter. The bitcoin address is the only representation of the keys that users will routinely see, because this is the part they need to share with the world.

First, we will introduce cryptography and explain the mathematics used in bitcoin. Next, we will look at how keys are generated, stored, and managed. Finally, we will look at advanced use of keys and addresses: vanity, multisignature, and script addresses and paper wallets.

Public Key Cryptography and Cryptocurrency Public key cryptography was invented in the s and is a mathematical foundation for computer and information security. Since the invention of public key cryptography, several suitable mathematical functions, such as prime number exponentiation and elliptic curve multiplication, have been discovered. These mathematical functions are practically irreversible, meaning that they are easy to calculate in one direction and infeasible to calculate in the opposite direction.

Based on these mathematical functions, cryptography enables the creation of digital secrets and unforgeable digital signatures. Bitcoin uses elliptic curve multiplication as the basis for its cryptography. In bitcoin, we use public key cryptography to create a key pair that controls access to bitcoin.

The key pair consists of a private key and—derived from it—a unique public key. The public key is used to receive funds, and the private key is used to sign transactions to spend the funds. There is a mathematical relationship between the public and the private key that allows the private key to be used to generate signatures on messages.

This signature can be validated against the public key without revealing the private key. When spending bitcoin, the current bitcoin owner presents her public key and a signature different each time, but created from the same private key in a transaction to spend those bitcoin.

Through the presentation of the public key and signature, everyone in the bitcoin network can verify and accept the transaction as valid, confirming that the person transferring the bitcoin owned them at the time of the transfer.

TIP In most wallet implementations, the private and public keys are stored together as a key pair for convenience. However, the public key can be calculated from the private key, so storing only the private key is also possible. Private and Public Keys A bitcoin wallet contains a collection of key pairs, each consisting of a private key and a public key.

The private key k is a number, usually picked at random. From the private key, we use elliptic curve multiplication, a one-way cryptographic function, to generate a public key K. From the public key K , we use a one-way cryptographic hash function to generate a bitcoin address A. In this section, we will start with generating the private key, look at the elliptic curve math that is used to turn that into a public key, and finally, generate a bitcoin address from the public key. The relationship between private key, public key, and bitcoin address is shown in Figure Why is asymmetric cryptography used in bitcoin?

Rather, the useful property of asymmetric cryptography is the ability to generate digital signatures. A private key can be applied to the digital fingerprint of a transaction to produce a numerical signature. This signature can only be produced by someone with knowledge of the private key. However, anyone with access to the public key and the transaction fingerprint can use them to verify the signature. This useful property of asymmetric cryptography makes it possible for anyone to verify every signature on every transaction, while ensuring that only the owners of private keys can produce valid signatures.

Private Keys A private key is simply a number, picked at random. Ownership and control over the private key is the root of user control over all funds associated with the corresponding bitcoin address. The private key is used to create signatures that are required to spend bitcoin by proving ownership of funds used in a transaction. The private key must remain secret at all times, because revealing it to third parties is equivalent to giving them control over the bitcoin secured by that key.

TIP The bitcoin private key is just a number. You can pick your private keys randomly using just a coin, pencil, and paper: toss a coin times and you have the binary digits of a random private key you can use in a bitcoin wallet. The public key can then be generated from the private key. Generating a private key from a random number The first and most important step in generating keys is to find a secure source of entropy, or randomness. Usually, the OS random number generator is initialized by a human source of randomness, which is why you may be asked to wiggle your mouse around for a few seconds.

To create such a key, we randomly pick a bit number and check that it is less than n - 1. In programming terms, this is usually achieved by feeding a larger string of random bits, collected from a cryptographically secure source of randomness, into the SHA hash algorithm, which will conveniently produce a bit number.

If the result is less than n - 1, we have a suitable private key. Otherwise, we simply try again with another random number. Study the documentation of the random number generator library you choose to make sure it is cryptographically secure. It is approximately in decimal. Considering the potential of the technology, it's imperative for companies and managers to get familiar with the Blockchain technology and comprehend how they can leverage it to transform their business operations.

It provides comprehensive coverage of Blockchain technology i. Concepts, Code and Cryptocurrencies. Last two chapters are dedicated to hand-on labs where we will browse live Ethereum Blockchain and develop, deploy and test few Smart Contracts using Solidity and Remix IDE. I wish you the very best in your Blockchain Journey! Now there might be some questions playing on your mind like: What is Bitcoin?

Why should I care? What the heck is blockchain? Is it secure? What can Bitcoin do that the dollar can't? Who benefits? How can I make money with bitcoin? Is Bitcoin doomed to fail? Do you suffer from future shock, but are looking for a reason to be optimistic? Do you see the possibility of something new and beautiful, but are unsure of it or how to articulate it to friends?

Then you have found the perfect book. It's an informative and entertaining read, and you may pick up some valuable tools and new ways of thinking you've never read or heard of before. Would You Like to Know More? Scroll to the top and click that buy button, and Get your copy Today! See you inside! Today only, get this Amazon bestseller for a special price. Read on your PC, Mac, smart phone, or tablet device. As an electronic resource, you can purchase bitcoins, claim them, and send them to another person.

Presently, there are above 14 million Bitcoins that have been made, expanding by 25 bitcoins like clockwork or thereabouts, with a concurred breaking point of 21 million, the remainder of which ought to be made a little before the year If You feel that this book is belong to you and you want to unpublish it, Please Contact us. Mastering Blockchain. Download e-Book. Posted on. Page Count. Imran Bashir,. Key Features Get to grips with the underlying technical principles and implementations of blockchain.



0コメント

  • 1000 / 1000