Antonopoulos mastering bitcoin programming the open blockchain index-of pdf
Mastering Bitcoin, 2nd Edition. by Andreas M. Antonopoulos. Released June Publisher(s): O'Reilly Media, Inc. ISBN. The sample transactions, blocks and blockchain references have all been introduced in the actual bitcoin blockchain and are part of the public ledger, so. PDF Title: Mastering Bitcoin, 2nd Edition. Total Page: Pages. Author: Andreas M. Antonopoulos. PDF Size: MB. Language: English. O2 ARENA BETTING SHOPS SCOTLAND
Later, as a professional, I developed my technical writing skills on the topic of data centers, writing for Network World magazine. I owe thanks to John Dix and John Gallant, who gave me my first writing job as a columnist at Network World and to my editor Michael Cooney and my colleague Johna Till Johnson who edited my columns and made them fit for publication.
Writing words a week for four years gave me enough experience to eventually consider becoming an author. Special thanks to Richard Kagan and Tymon Mattoszko, who reviewed early versions of the proposal and Matthew Taylor, who copyedited the proposal. Allyson was especially patient when deadlines were missed and deliverables delayed as life intervened in our planned schedule.
For the second edition, I thank Timothy McGovern for guiding the process, Kim Cofer for patiently editing, and Rebecca Panzer for illustrating many new diagrams. The first few drafts of the first few chapters were the hardest, because bitcoin is a difficult subject to unravel. Every time I pulled on one thread of the bitcoin technology, I had to pull on the whole thing.
I repeatedly got stuck and a bit despondent as I struggled to make the topic easy to understand and create a narrative around such a dense technical subject. Eventually, I decided to tell the story of bitcoin through the stories of the people using bitcoin and the whole book became a lot easier to write. I thank Pamela Morgan, who reviewed early drafts of each chapter in the first and second edition of the book, and asked the hard questions to make them better.
Thanks also to Andrew Naugler for infographic design. During the development of the book, I made early drafts available on GitHub and invited public comments. More than a hundred comments, suggestions, corrections, and contributions were submitted in response. Most of all, my sincere thanks to my volunteer GitHub editors Ming T.
Nguyen 1st edition and Will Binns 2nd edition , who worked tirelessly to curate, manage and resolve pull requests, issue reports, and perform bug fixes on GitHub. Once the book was drafted, it went through several rounds of technical review. Thanks to Cricket Liu and Lorne Lantz for their thorough review, comments, and support. Several bitcoin developers contributed code samples, reviews, comments, and encouragement. Thanks to Amir Taaki and Eric Voskuil for example code snippets and many great comments; Chris Kleeschulte for contributing the Bitcore appendix; Vitalik Buterin and Richard Kiss for help with elliptic curve math and code contributions; Gavin Andresen for corrections, comments, and encouragement; Michalis Kargakis for comments, contributions, and btcd writeup; and Robin Inge for errata submissions improving the second print.
In the second edition, I again received a lot of help from many Bitcoin Core developers, including Eric Lombrozo who demystified Segregated Witness, Luke-Jr who helped improve the chapter on transactions, Johnson Lau who reviewed Segregated Witness and other chapters, and many others. I owe my love of words and books to my mother, Theresa, who raised me in a house with books lining every wall.
My mother also bought me my first computer in , despite being a self-described technophobe. My father, Menelaos, a civil engineer who just published his first book at 80 years old, was the one who taught me logical and analytical thinking and a love of science and engineering. Thank you all for supporting me throughout this journey. Thank you all for your contributions to this book. Introduction What Is Bitcoin?
Bitcoin is a collection of concepts and technologies that form the basis of a digital money ecosystem. Units of currency called bitcoin are used to store and transmit value among participants in the bitcoin network. Bitcoin users communicate with each other using the bitcoin protocol primarily via the internet, although other transport networks can also be used. The bitcoin protocol stack, available as open source software, can be run on a wide range of computing devices, including laptops and smartphones, making the technology easily accessible.
Users can transfer bitcoin over the network to do just about anything that can be done with conventional currencies, including buy and sell goods, send money to people or organizations, or extend credit. Bitcoin can be purchased, sold, and exchanged for other currencies at specialized currency exchanges. Bitcoin in a sense is the perfect form of money for the internet because it is fast, secure, and borderless.
Unlike traditional currencies, bitcoin are entirely virtual. There are no physical coins or even digital coins per se. The coins are implied in transactions that transfer value from sender to recipient. Users of bitcoin own keys that allow them to prove ownership of bitcoin in the bitcoin network.
With these keys they can sign transactions to unlock the value and spend it by transferring it to a new owner. Possession of the key that can sign a transaction is the only prerequisite to spending bitcoin, putting the control entirely in the hands of each user. Bitcoin is a distributed, peer-to-peer system.
Any participant in the bitcoin network i. Every 10 minutes, on average, someone is able to validate the transactions of the past 10 minutes and is rewarded with brand new bitcoin. Essentially, bitcoin mining decentralizes the currency-issuance and clearing functions of a central bank and replaces the need for any central bank.
The bitcoin protocol includes built-in algorithms that regulate the mining function across the network. The difficulty of the processing task that miners must perform is adjusted dynamically so that, on average, someone succeeds every 10 minutes regardless of how many miners and how much processing are competing at any moment. The protocol also halves the rate at which new bitcoin are created every 4 years, and limits the total number of bitcoin that will be created to a fixed total just below 21 million coins.
The result is that the number of bitcoin in circulation closely follows an easily predictable curve that approaches 21 million by the year Behind the scenes, bitcoin is also the name of the protocol, a peer-to-peer network, and a distributed computing innovation. The bitcoin currency is really only the first application of this invention. Bitcoin represents the culmination of decades of research in cryptography and distributed systems and includes four key innovations brought together in a unique and powerful combination.
Bitcoin consists of: A decentralized peer-to-peer network the bitcoin protocol A public transaction ledger the blockchain A set of rules for independent transaction validation and currency issuance consensus rules A mechanism for reaching global decentralized consensus on the valid blockchain Proof-of-Work algorithm As a developer, I see bitcoin as akin to the internet of money, a network for propagating value and securing the ownership of digital assets via distributed computation.
This is not surprising when one considers the fundamental challenges involved with using bits to represent value that can be exchanged for goods and services. Three basic questions for anyone accepting digital money are: 1.
Can I trust that the money is authentic and not counterfeit? Can I be sure that no one else can claim this money belongs to them and not me? Issuers of paper money are constantly battling the counterfeiting problem by using increasingly sophisticated papers and printing technology.
Physical money addresses the double-spend issue easily because the same paper note cannot be in two places at once. Of course, conventional money is also often stored and transmitted digitally. In these cases, the counterfeiting and double-spend issues are handled by clearing all electronic transactions through central authorities that have a global view of the currency in circulation. Specifically, cryptographic digital signatures enable a user to sign a digital asset or transaction proving the ownership of that asset.
With the appropriate architecture, digital signatures also can be used to address the double-spend issue. When cryptography started becoming more broadly available and understood in the late s, many researchers began trying to use cryptography to build digital currencies. These early digital currency projects issued digital money, usually backed by a national currency or precious metal such as gold. Although these earlier digital currencies worked, they were centralized and, as a result, were easy to attack by governments and hackers.
Early digital currencies used a central clearinghouse to settle all transactions at regular intervals, just like a traditional banking system. Unfortunately, in most cases these nascent digital currencies were targeted by worried governments and eventually litigated out of existence. Some failed in spectacular crashes when the parent company liquidated abruptly.
To be robust against intervention by antagonists, whether legitimate governments or criminal elements, a decentralized digital currency was needed to avoid a single point of attack. Bitcoin is such a system, decentralized by design, and free of any central authority or point of control that can be attacked or corrupted.
Nakamoto combined several prior inventions such as b-money and HashCash to create a completely decentralized electronic cash system that does not rely on a central authority for currency issuance or settlement and validation of transactions. This elegantly solves the issue of double-spend where a single currency unit can be spent twice.
Previously, the double-spend problem was a weakness of digital currency and was addressed by clearing all transactions through a central clearinghouse. The bitcoin network started in , based on a reference implementation published by Nakamoto and since revised by many other programmers.
Satoshi Nakamoto withdrew from the public in April , leaving the responsibility of developing the code and network to a thriving group of volunteers. The identity of the person or people behind bitcoin is still unknown. However, neither Satoshi Nakamoto nor anyone else exerts individual control over the bitcoin system, which operates based on fully transparent mathematical principles, open source code, and consensus among participants. The invention itself is groundbreaking and has already spawned new science in the fields of distributed computing, economics, and econometrics.
It can be used to achieve consensus on decentralized networks to prove the fairness of elections, lotteries, asset registries, digital notarization, and more. At its core, money simply facilitates the exchange of value between people. Each of the people and their stories, as listed here, illustrates one or more specific use cases. She has heard about bitcoin from her techie friends and wants to start using it.
This story will introduce us to the software, the exchanges, and basic transactions from the perspective of a retail consumer. North American high-value retail Carol is an art gallery owner in San Francisco. She sells expensive paintings for bitcoin. Offshore contract services Bob, the cafe owner in Palo Alto, is building a new website. He has contracted with an Indian web developer, Gopesh, who lives in Bangalore, India.
Gopesh has agreed to be paid in bitcoin. This story will examine the use of bitcoin for outsourcing, contract services, and international wire transfers. Web store Gabriel is an enterprising young teenager in Rio de Janeiro, running a small web store that sells bitcoin-branded t-shirts, coffee mugs, and stickers. Gabriel is too young to have a bank account, but his parents are encouraging his entrepreneurial spirit. Recently she has discovered bitcoin and wants to use it to reach a whole new group of foreign and domestic donors to fundraise for her charity.
This story will show the use of bitcoin for global fundraising across currencies and borders and the use of an open ledger for transparency in charitable organizations. This story will show how bitcoin can be used for large business-to-business international payments tied to physical goods.
Mining for bitcoin Jing is a computer engineering student in Shanghai. Each of these stories is based on the real people and real industries currently using bitcoin to create new markets, new industries, and innovative solutions to global economic issues. Getting Started Bitcoin is a protocol that can be accessed using a client application that speaks the protocol. There are many implementations and brands of bitcoin wallets, just like there are many brands of web browsers e.
And just like we all have our favorite browsers Mozilla Firefox, Yay! Choosing a Bitcoin Wallet Bitcoin wallets are one of the most actively developed applications in the bitcoin ecosystem. There is intense competition, and while a new wallet is probably being developed right now, several wallets from last year are no longer actively maintained. Many wallets focus on specific platforms or specific uses and some are more suitable for beginners while others are filled with features for advanced users.
Choosing a wallet is highly subjective and depends on the use and user expertise. It is therefore impossible to recommend a specific brand or project of wallet. However, we can categorize bitcoin wallets according to their platform and function and provide some clarity about all the different types of wallets that exist.
Better yet, moving money between bitcoin wallets is easy, cheap, and fast, so it is worth trying out several different wallets until you find one that fits your needs. Bitcoin wallets can be categorized as follows, according to the platform: Desktop wallet A desktop wallet was the first type of bitcoin wallet created as a reference implementation and many users run desktop wallets for the features, autonomy, and control they offer.
Running on general-use operating systems such as Windows and Mac OS has certain security disadvantages however, as these platforms are often insecure and poorly configured. Mobile wallet A mobile wallet is the most common type of bitcoin wallet. Running on smart-phone operating systems such as Apple iOS and Android, these wallets are often a great choice for new users.
Many are designed for simplicity and ease-of-use, but there are also fully featured mobile wallets for power users. This is similar to webmail in that it relies entirely on a third-party server. Most, however, present a compromise by taking control of the bitcoin keys from users in exchange for ease-of-use. It is inadvisable to store large amounts of bitcoin on third-party systems. Hardware wallet Hardware wallets are devices that operate a secure self-contained bitcoin wallet on special-purpose hardware.
By handling all bitcoin-related operations on the specialized hardware, these wallets are considered very secure and suitable for storing large amounts of bitcoin. Paper wallet The keys controlling bitcoin can also be printed for long-term storage. These are known as paper wallets even though other materials wood, metal, etc. Paper wallets offer a low-tech but highly secure means of storing bitcoin long term. Offline storage is also often referred to as cold storage.
A full node handles all aspects of the protocol and can independently validate the entire blockchain and any transaction. A full-node client consumes substantial computer resources e. Lightweight client A lightweight client, also known as a simple-payment-verification SPV client, connects to bitcoin full nodes mentioned previously for access to the bitcoin transaction information, but stores the user wallet locally and independently creates, validates, and transmits transactions.
Lightweight clients interact directly with the bitcoin network, without an intermediary. Third-party API client A third-party API client is one that interacts with bitcoin through a third-party system of application programming interfaces APIs , rather than by connecting to the bitcoin network directly. The wallet may be stored by the user or by third-party servers, but all transactions go through a third party. Combining these categorizations, many bitcoin wallets fall into a few groups, with the three most common being desktop full client, mobile lightweight wallet, and web third-party wallet.
The lines between different categories are often blurry, as many wallets run on multiple platforms and can interact with the network in different ways. For the purposes of this book, we will be demonstrating the use of a variety of downloadable bitcoin clients, from the reference implementation Bitcoin Core to mobile and web wallets.
Some of the examples will require the use of Bitcoin Core, which, in addition to being a full client, also exposes APIs to the wallet, network, and transaction services. While at a party, Joe is once again enthusiastically explaining bitcoin to all around him and is offering a demonstration. Intrigued, Alice asks how she can get started with bitcoin.
Joe says that a mobile wallet is best for new users and he recommends a few of his favorite wallets. When Alice runs Mycelium for the first time, as with many bitcoin wallets, the application automatically creates a new wallet for her. Alice sees the wallet on her screen, as shown in Figure note: do not send bitcoin to this sample address, it will be lost forever.
Figure The QR code is the square with a pattern of black and white dots. Alice can copy the bitcoin address or the QR code onto her clipboard by tapping the QR code, or the Receive button. In most wallets, tapping the QR code will also magnify it, so that it can be more easily scanned by a smartphone camera. TIP Bitcoin addresses start with a 1 or 3. Like email addresses, they can be shared with other bitcoin users who can use them to send bitcoin directly to your wallet.
There is nothing sensitive, from a security perspective, about the bitcoin address. It can be posted anywhere without risking the security of the account. Unlike email addresses, you can create new addresses as often as you like, all of which will direct funds to your wallet. In fact, many modern wallets automatically create a new address for every transaction to maximize privacy.
A wallet is simply a collection of addresses and the keys that unlock the funds within. Alice is now ready to receive funds. Her bitcoin address is simply a number that corresponds to a key that she can use to control access to the funds. It was generated independently by her wallet without reference or registration with any service. Until the moment this address is referenced as the recipient of value in a transaction posted on the bitcoin ledger, the bitcoin address is simply part of the vast number of possible addresses that are valid in bitcoin.
Only once it has been associated with a transaction does it become part of the known addresses in the network. Alice is now ready to start using her new bitcoin wallet. Getting Your First Bitcoin The first and often most difficult task for new users is to acquire some bitcoin. Unlike other foreign currencies, you cannot yet buy bitcoin at a bank or foreign exchange kiosk.
Bitcoin transactions are irreversible. Most electronic payment networks such as credit cards, debit cards, PayPal, and bank account transfers are reversible. For someone selling bitcoin, this difference introduces a very high risk that the buyer will reverse the electronic payment after they have received bitcoin, in effect defrauding the seller. To mitigate this risk, companies accepting traditional electronic payments in return for bitcoin usually require buyers to undergo identity verification and credit-worthiness checks, which may take several days or weeks.
As a new user, this means you cannot buy bitcoin instantly with a credit card. Here are some methods for getting bitcoin as a new user: Find a friend who has bitcoin and buy some from him or her directly. Many bitcoin users start this way. This method is the least complicated. One way to meet people with bitcoin is to attend a local bitcoin meetup listed at Meetup. Use a classified service such as localbitcoins. Earn bitcoin by selling a product or service for bitcoin.
If you are a programmer, sell your programming skills. Use a bitcoin ATM in your city. A bitcoin ATM is a machine that accepts cash and sends bitcoin to your smartphone bitcoin wallet. Use a bitcoin currency exchange linked to your bank account. Many countries now have currency exchanges that offer a market for buyers and sellers to swap bitcoin with local currency.
Exchange-rate listing services, such as BitcoinAverage, often show a list of bitcoin exchanges for each currency. TIP One of the advantages of bitcoin over other payment systems is that, when used correctly, it affords users much more privacy. Acquiring, holding, and spending bitcoin does not require you to divulge sensitive and personally identifiable information to third parties.
However, where bitcoin touches traditional systems, such as currency exchanges, national and international regulations often apply. In order to exchange bitcoin for your national currency, you will often be required to provide proof of identity and banking information. Users should be aware that once a bitcoin address is attached to an identity, all associated bitcoin transactions are also easy to identify and track.
This is one reason many users choose to maintain dedicated exchange accounts unlinked to their wallets. Alice was introduced to bitcoin by a friend so she has an easy way to acquire her first bitcoin. Next, we will look at how she buys bitcoin from her friend Joe and how Joe sends the bitcoin to her wallet. Bitcoin, like most other currencies, has a floating exchange rate.
That means that the value of bitcoin visa-vis any other currency fluctuates according to supply and demand in the various markets where it is traded. As such, the price tends to fluctuate minutely several times per second. A pricing service will aggregate the prices from several markets and calculate a volumeweighted average representing the broad market exchange rate of a currency pair e. There are hundreds of applications and websites that can provide the current market rate.
Here are some of the most popular: Bitcoin Average A site that provides a simple view of the volume-weighted-average for each currency. CoinCap A service listing the market capitalization and exchange rates of hundreds of crypto-currencies, including bitcoin. Chicago Mercantile Exchange Bitcoin Reference Rate A reference rate that can be used for institutional and contractual reference, provided as part of investment data feeds by the CME. In addition to these various sites and applications, most bitcoin wallets will automatically convert amounts between bitcoin and other currencies.
Joe will use his wallet to convert the price automatically before sending bitcoin to Alice. Joe then selects Send on his smartphone wallet and is presented with a screen containing two inputs: A destination bitcoin address The amount to send, in bitcoin BTC or his local currency USD In the input field for the bitcoin address, there is a small icon that looks like a QR code.
Airbitz mobile bitcoin wallet send screen Joe then carefully checks to make sure he has entered the correct amount, because he is about to transmit money and mistakes are irreversible. After double-checking the address and amount, he presses Send to transmit the transaction. As the transaction is transmitted via the peer-to-peer protocol, it quickly propagates across the bitcoin network.
To be confirmed, a transaction must be included in a block and added to the blockchain, which happens every 10 minutes, on average. In traditional financial terms this is known as clearing. For more details on propagation, validation, and clearing confirmation of bitcoin transactions, see Chapter Alice is now the proud owner of 0. In the next chapter we will look at her first purchase with bitcoin, and examine the underlying transaction and propagation technologies in more detail.
Chapter 2. How Bitcoin Works Transactions, Blocks, Mining, and the Blockchain The bitcoin system, unlike traditional banking and payment systems, is based on decentralized trust. Instead of a central trusted authority, in bitcoin, trust is achieved as an emergent property from the interactions of different participants in the bitcoin system.
Subsequent chapters will delve into the technology behind transactions, the network, and mining. Bitcoin Overview In the overview diagram shown in Figure , we see that the bitcoin system consists of users with wallets containing keys, transactions that are propagated across the network, and miners who produce through competitive computation the consensus blockchain, which is the authoritative ledger of all transactions.
Each example in this chapter is based on an actual transaction made on the bitcoin network, simulating the interactions between the users Joe, Alice, Bob, and Gopesh by sending funds from one wallet to another. While tracking a transaction through the bitcoin network to the blockchain, we will use a blockchain explorer site to visualize each step. A blockchain explorer is a web application that operates as a bitcoin search engine, in that it allows you to search for addresses, transactions, and blocks and see the relationships and flows between them.
With each transaction or block example, we will provide a URL so you can look it up yourself and study it in detail. Buying a Cup of Coffee Alice, introduced in the previous chapter, is a new user who has just acquired her first bitcoin. Alice places her order for a cup of coffee and Bob enters it into the register, as he does for all transactions. You can scan the QR code with a bitcoin wallet application to see what Alice would see. Her smartphone shows a payment of 0.
Within a few seconds about the same amount of time as a credit card authorization , Bob sees the transaction on the register, completing the transaction. In the following sections we will examine this transaction in more detail. NOTE The bitcoin network can transact in fractional values, e.
The new owner can now spend the bitcoin by creating another transaction that authorizes transfer to another owner, and so on, in a chain of ownership. Transaction Inputs and Outputs Transactions are like lines in a double-entry bookkeeping ledger. The inputs and outputs debits and credits do not necessarily add up to the same amount. Instead, outputs add up to slightly less than inputs and the difference represents an implied transaction fee, which is a small payment collected by the miner who includes the transaction in the ledger.
A bitcoin transaction is shown as a bookkeeping ledger entry in Figure The transaction also contains proof of ownership for each amount of bitcoin inputs whose value is being spent, in the form of a digital signature from the owner, which can be independently validated by anyone. In the previous chapter, Alice received bitcoin from her friend Joe in return for cash. The transactions form a chain, where the inputs from the latest transaction correspond to outputs from previous transactions.
This represents a transfer of value between Alice and Bob. This chain of transactions, from Joe to Alice to Bob, is illustrated in Figure A chain of transactions, where the output of one transaction is the input of the next transaction Making Change Many bitcoin transactions will include outputs that reference both an address of the new owner and an address of the current owner, called the change address.
This is because transaction inputs, like currency notes, cannot be divided. The same concept applies with bitcoin transaction inputs. If you purchased an item that costs 5 bitcoin but only had a 20 bitcoin input to use, you would send one output of 5 bitcoin to the store owner and one output of 15 bitcoin back to yourself as change less any applicable transaction fee. Different wallets may use different strategies when aggregating inputs to make a payment requested by the user.
They might aggregate many small inputs, or use one that is equal to or larger than the desired payment. Unless the wallet can aggregate inputs in such a way to exactly match the desired payment plus transaction fees, the wallet will need to generate some change.
This is very similar to how people handle cash. If you always use the largest bill in your pocket, you will end up with a pocket full of loose change. People subconsciously find a balance between these two extremes, and bitcoin wallet developers strive to program this balance. In summary, transactions move value from transaction inputs to transaction outputs. Outputs from one transaction can be used as inputs in a new transaction, thus creating a chain of ownership as the value is moved from owner to owner see Figure This type of transaction has one input and two outputs and is shown in Figure Most common transaction Another common form of transaction is one that aggregates several inputs into a single output see Figure This represents the real-world equivalent of exchanging a pile of coins and currency notes for a single larger note.
Transactions like these are sometimes generated by wallet applications to clean up lots of smaller amounts that were received as change for payments. Transaction aggregating funds Finally, another transaction form that is seen often on the bitcoin ledger is a transaction that distributes one input to multiple outputs representing multiple recipients see Figure This type of transaction is sometimes used by commercial entities to distribute funds, such as when processing payroll payments to multiple employees.
Alice only needs to specify a destination and an amount, and the rest happens in the wallet application without her seeing the details. Importantly, a wallet application can construct transactions even if it is completely offline. Like writing a check at home and later sending it to the bank in an envelope, the transaction does not need to be constructed and signed while connected to the bitcoin network.
Most wallets keep track of all the available outputs belonging to addresses in the wallet. A bitcoin wallet application that runs as a fullnode client actually contains a copy of every unspent output from every transaction in the blockchain. This allows a wallet to construct transaction inputs as well as quickly verify incoming transactions as having correct inputs. If the wallet application does not maintain a copy of unspent transaction outputs, it can query the bitcoin network to retrieve this information using a variety of APIs available by different providers or by asking a full-node using an application programming interface API call.
This URL will return all the unspent transaction outputs for an address, giving any application the information it needs to construct transaction inputs for spending. Example The response includes the reference to the transaction in which this unspent output is contained the payment from Joe and its value in satoshis, at 10 million, equivalent to 0. In both cases, there might be a need to get some change back, which we will see in the next section, as the wallet application creates the transaction outputs payments.
Creating the Outputs A transaction output is created in the form of a script that creates an encumbrance on the value and can only be redeemed by the introduction of a solution to the script. Alice will need 0.
She can then use spend the change output in a subsequent transaction. This is not explicit in the transaction; it is implied by the difference between inputs and outputs. If instead of taking 0. The resulting difference is the transaction fee that is collected by the miner as a fee for validating and including the transaction in a block to be recorded on the blockchain. The resulting transaction can be seen using a blockchain explorer web application, as shown in Figure Now, the transaction must be transmitted to the bitcoin network where it will become part of the blockchain.
Transmitting the transaction Because the transaction contains all the information necessary to process, it does not matter how or where it is transmitted to the bitcoin network. The bitcoin network is a peer-to-peer network, with each bitcoin client participating by connecting to several other bitcoin clients.
The purpose of the bitcoin network is to propagate transactions and blocks to all participants. Any bitcoin node that receives a valid transaction it has not seen before will immediately forward it to all other nodes to which it is connected, a propagation technique known as flooding. Thus, the transaction rapidly propagates out across the peer-to-peer network, reaching a large percentage of the nodes within a few seconds.
At this point Bob can assume, with little risk, that the transaction will shortly be included in a block and confirmed. Although confirmations ensure the transaction has been accepted by the whole network, such a delay is unnecessary for small-value items such as a cup of coffee. A merchant may accept a valid small-value transaction with no confirmations, with no more risk than a credit card payment made without an ID or a signature, as merchants routinely accept today.
It does not become part of the blockchain until it is verified and included in a block by a process called mining. See Chapter 10 for a detailed explanation. The bitcoin system of trust is based on computation. Transactions are bundled into blocks, which require an enormous amount of computation to prove, but only a small amount of computation to verify as proven. Therefore, mining provides security for bitcoin transactions by rejecting invalid or malformed transactions. Mining creates new bitcoin in each block, almost like a central bank printing new money.
The amount of bitcoin created per block is limited and diminishes with time, following a fixed issuance schedule. Mining achieves a fine balance between cost and reward. Mining uses electricity to solve a mathematical problem. A successful miner will collect a reward in the form of new bitcoin and transaction fees.
However, the reward will only be collected if the miner has correctly validated all the transactions, to the satisfaction of the rules of consensus. This delicate balance provides security for bitcoin without a central authority. A good way to describe mining is like a giant competitive game of sudoku that resets every time someone finds a solution and whose difficulty automatically adjusts so that it takes approximately 10 minutes to find a solution.
Imagine a giant sudoku puzzle, several thousand rows and columns in size. If I show you a completed puzzle you can verify it quite quickly. However, if the puzzle has a few squares filled and the rest are empty, it takes a lot of work to solve!
The difficulty of the sudoku can be adjusted by changing its size more or fewer rows and columns , but it can still be verified quite easily even if it is very large. Jing runs a mining farm, which is a business that runs thousands of specialized mining computers, competing for the reward. Finding such a solution, the so-called Proof-ofWork PoW , requires quadrillions of hashing operations per second across the entire bitcoin network. 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. These commands will return the exact same hex string that we produced and decoded previously just before we sent it on the network.
Alternative Clients, Libraries, and Toolkits Beyond the reference client bitcoind , other clients and libraries can be used to interact with the bitcoin network and data structures. These are implemented in a variety of programming languages, offering programmers native interfaces in their own language. The sx tools also offer some key management and manipulation tools that are not offered by bitcoind, including type-2 deterministic keys and key mnemonics.
Type sx with no parameters to display the help text, which lists all the available commands see Appendix D. Use them to explore the various formats such as Base58, Base58Check, hex, etc. The pycoin library supports both Python 2 2. To install pycoin 0. It also properly relays newly mined blocks, maintains a transaction pool, and relays individual transactions that have not yet made it into a block.
That functionality is provided by the btcwallet and btcgui projects, which are both under active development. 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. Every bitcoin transaction requires a valid signature to be included in the blockchain, which can only be generated with valid digital keys; therefore, anyone with a copy of those keys has control of the bitcoin in that account.
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.
In this chapter we will introduce wallets, which contain cryptographic keys. We will look at how keys are generated, stored, and managed. Finally, we will look at special uses of keys: to sign messages, to prove ownership, and to create vanity 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.
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 public key cryptography. In bitcoin, we use public key cryptography to create a key pair that controls access to bitcoins. The key pair consists of a private key and—derived from it—a unique public key.
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. However, the public key can be calculated from the private key, so storing only the private key is also possible.
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 Figure Private key, public key, and bitcoin address 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 bitcoins 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 bitcoins secured by that key. 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.
For the truly paranoid, nothing beats dice, pencil, and paper. 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 that 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.
It is approximately in decimal. The visible universe is estimated to contain atoms. To generate a new key with the Bitcoin Core client see Chapter 3 , use the getnewad dress command. For security reasons it displays the public key only, not the private key. To ask bitcoind to expose the private key, use the dumpprivkey command.
It is not otherwise possible for bitcoind to know the private key from the public key, unless they are both stored in the wallet. The dumpprivkey command is not generating a private key from a public key, as this is impossible. Elliptic Curve Cryptography Explained Elliptic curve cryptography is a type of asymmetric or public-key cryptography based on the discrete logarithm problem as expressed by addition and multiplication on the points of an elliptic curve.
Figure is an example of an elliptic curve, similar to that used by bitcoin. Introduction 65 Figure Because this curve is defined over a finite field of prime order instead of over the real numbers, it looks like a pattern of dots scattered in two dimensions, which makes it difficult to visualize. However, the math is identical as that of an elliptic curve over the real numbers. As an example, Figure shows the same elliptic curve over a much smaller finite field of prime order 17, showing a pattern of dots on a grid.
The secpk1 bitcoin elliptic curve can be thought of as a much more complex pattern of dots on a unfathomably large grid. Geometrically, this third point P3 is calculated by drawing a line between P1 and P2. This line will intersect the elliptic curve in exactly one additional place. This tangent will intersect the curve in exactly one new point. You can use techniques from calculus to determine the slope of the tangent line.
These techniques curiously work, even though we are restricting our interest to points on the curve with two integer coordinates! In some cases i. This shows how the point at infinity plays the role of 0. Now that we have defined addition, we can define multiplication in the standard way that extends addition. Generating a Public Key Starting with a private key in the form of a randomly generated number k, we multiply it by a predetermined point on the curve called the generator point G to produce another point somewhere else on the curve, which is the corresponding public key K.
Because the generator point is always the same for all bitcoin users, 68 Chapter 4: Keys, Addresses, Wallets a private key k multiplied with G will always result in the same public key K. A private key can be converted into a public key, but a public key cannot be converted back into a private key because the math only works one way. Our goal is to find the multiple kG of the generator point G. That is the same as adding G to itself, k times in a row. In elliptic curves, adding a point to itself is the equivalent of drawing a tangent line on the point and finding where it intersects the curve again, then reflecting that point on the x-axis.
Figure shows the process for deriving G, 2G, 4G, as a geometric operation on the curve. Introduction 69 Figure Elliptic curve cryptography: Visualizing the multiplication of a point G by an integer k on an elliptic curve Bitcoin Addresses A bitcoin address is a string of digits and characters that can be shared with anyone who wants to send you money.
Suggest you betting tips football draws have
WHERE CAN I USE BITCOIN IN AUSTRALIA
Table " country " Having a it has become a convenient way to connect with. On lan option, able address and resolve inquiries relating. Put your PC and public disclosure. That theres no are located in into a terminal.
Antonopoulos mastering bitcoin programming the open blockchain index-of pdf distances between places south downs wayConsensus Algorithms, Blockchain Technology and Bitcoin UCL - by Andreas M. Antonopoulos
Antonopoulos Mastering Bitcoin by Andreas M.
|Football accumulator tips olbg betting||966|
|Glycol ethers dangers epa website||2007 packers seahawks betting|
|In play betting tipster||78|
|Konsisten forex||Bitcoin cipher|
|Crypto programming jobs||827|
comments: 2 на “Antonopoulos mastering bitcoin programming the open blockchain index-of pdf”
btc faucet design
slavia sofia vs montana betting tips