How do Bitcoin transactions work?

 Bitcoin was created to function as peer-to-peer electronic cash. Whether you are spending or accepting bitcoin as payment, it is prudent to understand how a transaction works.

Bitcoin transactions are messages, like email, which are digitally signed using cryptography and sent to the entire Bitcoin network for verification. Transaction information is public and can be found on the digital ledger known as the 'blockchain.' The history of each and every Bitcoin transaction leads back to the point where the bitcoins were first produced or 'mined.'

Public and private keys

To send Bitcoin, you must have access to the public and private keys associated with the amount of bitcoin you want to send. When we talk of someone "owning" bitcoins, what it actually means is that person has access to a 'key pair' comprised of:

a public key (an address) to which some amount bitcoin was previously sent

the corresponding unique private key (a password) which authorizes the bitcoin previously sent to the above public key (address) to be sent elsewhere.

Public keys, also called bitcoin addresses, are randomly generated sequences of letters and numbers that function similarly to an email address or a social-media site username. As the name implies, they are public, so you are safe sharing them with others. In fact, you must give your Bitcoin address to others when you want them to send you bitcoin. The private key is another sequence of letters and numbers, also generated randomly. However, private keys, like passwords to email or other accounts, are to be kept secret. Never share your private key with anyone that you do not 100% trust to not steal from you.

You can think of your Bitcoin address as a transparent safe. Others can see what's inside, but only those with the private key can unlock the safe to access the funds within.

Transaction inputs and outputs

Although it would be possible to handle coins individually, it would be unwieldy to make a separate transaction for every cent in a transfer. To allow value to be split and combined, transactions contain multiple inputs and outputs. Normally there will be either a single input from a larger previous transaction or multiple inputs combining smaller amounts, and at most two outputs: one for the payment, and one returning the change, if any, back to the sender

—Satoshi Nakamoto, Bitcoin white paper

Let's break down that section of the Bitcoin white paper by looking at a sample transaction in practice:

Mark wants to send 1 BTC to Jessica. To do this, he uses his private key to 'sign' a message with the transaction-specific details. This message, which must be broadcast to the network, will contain the following:

  • Inputs. This contains information about the bitcoin previously sent to Mark's address. For example, imagine Mark previously received 0.6 BTC from Alice and 0.6 BTC from Bob. Now, in order to send 1 BTC to Jessica, there might be two inputs: one input of 0.6 BTC previously from Alice and one input of 0.6 BTC previously from Bob.
  • Amount. In this case, the amount Mark wants to send is 1 BTC.
  • Outputs. There are two outputs. The first is 1 BTC to Jessica’s address. The second is 0.2 BTC returned as 'change' to Mark. This second output is calculated as the total of the inputs [0.6 + 0.6 = 1.2], minus the amount Mark wants to send [1 BTC].
  • This might seem confusing, but it's done this way to improve efficiency - and the good news is that knowing the behind-the-scenes details of Bitcoin transactions is not required to send or receive bitcoin. Your Bitcoin Wallet takes care of that!

Broadcasting and confirmations

In the above example, Mark (via his wallet software) will broadcast his proposed transaction to the Bitcoin network. A special group of participants in the network known as 'miners' verify that Mark's keys are able to access the inputs (i.e. the address(s) from where he previously received the bitcoin he claims to control. Miners also gather together a list of other transactions that were broadcast to the network around the same time as Mark's and form them into a block. Any miner who has completed the 'Proof of Work' is permitted to propose a new block that will be added or 'attached' to the chain and by referencing the last block. That new block is then broadcast to the network. If other network participants (nodes) agree it's a valid block (ie. the transactions it contains follows all the rules of the protocol and it properly references the previous block), they will pass it along. Eventually, another miner will build on top of it by referencing it as the previous block when proposing the next block. Any transactions that were in the previous block will now have been 'confirmed' by the next miner. As blocks are added to the chain, the number of confirmations of Mark's transaction increases.

Why do some bitcoin transaction confirmations take so long?

Each block can only contain a certain number of transactions, and that number is determined largely by the space available in each block, or the 'block size,' which is 1MB. The limited space gives rise to the fee market, where miners, who collect fees, choose to include in the next block only those transactions which have included a high enough fee. Thus higher fees act as incentive for miners to prioritize your transactions.

Note that the block size is an arbitrary limit, but the Bitcoin community has chosen to keep the block size as small as possible in order to make it easier for people to operate Bitcoin nodes. Bitcoin Cash, which is a fork of Bitcoin, has a larger block size and therefore requires (much) lower fees for transactions.

How much are bitcoin transaction fees?

Fees for sending bitcoin could be anywhere from a few cents all the way up to $100. The reason for the big variation is that Bitcoin fees depend on both supply and demand (ie. how congested the network is at a given time) and the "size" of your transaction. Size is affected primarily by inputs, so if your transaction has many inputs, it will take up more block space, and demand a higher fee. For example, if you want to send 10 BTC, there's a good chance your transaction will require more inputs than if you want to send 1 BTC. The 10 BTC transaction might consist of 5+2+1+1+1 (so a total of 5 inputs) while the 1 BTC transaction might be just two inputs as in our Mark/Jessica example above.

Many wallets, including the Bitcoin Wallet, allow users to manually set transaction fees. This helps you to avoid overpaying. For example, if you're not in a rush, you can set the fee the lower such that it will be picked up by a miner when the network is less congested. You can also ensure your transactions are processed immediately by increasing your fee.

Comments

Popular posts from this blog

Why Is Crypto Crashing? Here’s What You Should Know Right Now

What is cryptocurrency? A beginner’s guide to digital currency

What is cryptocurrency?