суббота, 16 июня 2018 г.

bitcoin_transaktion

A visualisation of live Bitcoin transactions from the Blockchain

Every time a Bitcoin transaction is made it is shown here as coloured ball dropping on the plate, You can click on the transactions to find out exactly how much they are worth in BTC. The the cubes represent the last block from the blockchain which are mined on average every 10 minutes, the size of the block is determined by its size in Kilobytes.

Why do they keep falling off the plate? That is so that your browser doesn't crash but if things are getting too much just press the space bar!

This is made using using the awesome three.js and oimo.js Javascript libraries, and live streaming Bitcoin transaction data from blockchain.info. This demo uses quite experimental browser techniques and works best in the Google Chrome browser

I made this for a bit of fun, If you like it please pass it on. Donations will encourage me to make more fun Bitcoin related stuff!

How do Bitcoin Transactions Work?

Last updated: 29th January 2018

If I want to send some of my bitcoin to you, I publish my intention and the nodes scan the entire bitcoin network to validate that I 1) have the bitcoin that I want to send, and 2) haven't already sent it to someone else. Once that information is confirmed, my transaction gets included in a "block" which gets attached to the previous block - hence the term "blockchain." Transactions can't be undone or tampered with, because it would mean re-doing all the blocks that came after.

Getting a bit more complicated:

My bitcoin wallet doesn't actually hold my bitcoin. What it does is hold my bitcoin address, which keeps a record of all of my transactions, and therefore of my balance. This address – a long string of 34 letters and numbers – is also known as my "public key." I don't mind that the whole world can see this sequence. Each address/public key has a corresponding "private key" of 64 letters and numbers. This is private, and it's crucial that I keep it secret and safe. The two keys are related, but there's no way that you can figure out my private key from my public key.

That's important, because any transaction I issue from my bitcoin address needs to be "signed" with my private key. To do that, I put both my private key and the transaction details (how many bitcoins I want to send, and to whom) into the bitcoin software on my computer or smartphone.

With this information, the program spits out a digital signature, which gets sent out to the network for validation.

This transaction can be validated – that is, it can be confirmed that I own the bitcoin that I am transferring to you, and that I haven't already sent it to someone else – by plugging the signature and my public key (which everyone knows) into the bitcoin program. This is one of the genius parts of bitcoin: if the signature was made with the private key that corresponds to that public key, the program will validate the transaction, without knowing what the private key is. Very clever.

The network then confirms that I haven't previously spent the bitcoin by running through my address history, which it can do because it knows my address (= my public key), and because all transactions are public on the bitcoin ledger.

Even more complicated:

Once my transaction has been validated, it gets included into a "block," along with a bunch of other transactions.

A brief detour to discuss what a "hash" is, because it's important for the next paragraph: a hash is produced by a "hash function," which is a complex math equation that reduces any amount of text or data to 64-character string. It's not random – every time you put in that particular data set through the hash function, you'll get the same 64-character string. But if you change so much as a comma, you'll get a completely different 64-character string. This whole article could be reduced to a hash, and unless I change, remove or add anything to the text, the same hash can be produced again and again. This is a very effective way to tell if something has been changed, and is how the blockchain can confirm that a transaction has not been tampered with.

Back to our blocks: each block includes, as part of its data, a hash of the previous block. That's what makes it part of a chain, hence the term "blockchain." So, if one small part of the previous block was tampered with, the current block's hash would have to change (remember that one tiny change in the input of the hash function changes the output). So if you want to change something in the previous block, you also have to change something (= the hash) in the current block, because the one that is currently included is no longer correct. That's very hard to do, especially since by the time you've reached half way, there's probably another block on top of the current one. You'd then also have to change that one. And so on.

This is what makes Bitcoin virtually tamper-proof. I say virtually because it's not impossible, just very very, very, very, very difficult and therefore unlikely.

And if you want to indulge in some mindless fascination, you can sit at your desk and watch bitcoin transactions float by. Blockchain.info is good for this, but if you want a hypnotically fun version, try BitBonkers.

(For more detail on how blocks are processed and on how bitcoin mining works, see this article.)

What to Do if Your Bitcoin Transaction Gets "Stuck"

The number of transactions on the Bitcoin network has steadily increased over the years. This means more blocks are filling up. And as not all transactions can be included in the blockchain straight away, backlogs form in miners’ “mempools” (a sort of “transaction queue.”)

Miners typically pick the transactions that pay the most fees and include these in their blocks first. Transactions that include lower fees are “outbid” on the so called “fee market,” and remain in miners’ mempools until a new block is found. If the transaction is outbid again, it has to wait until the next block.

This can lead to a suboptimal user experience. Transactions with too low a fee can take hours or even days to confirm, and sometimes never confirm at all.

But here is what you can do today to keep your own transaction from getting stuck.

Before You Send It

For the first years of Bitcoin’s existence, most wallets added fixed fees to outgoing transactions: typically, 0.1 mBTC. Since miners had spare space in their blocks anyways, they normally included these transactions in the first block they mined. (In fact, transactions with lower fees or even no fee at all were often included as well.)

With the increased competition for block space, a fixed 0.1 mBTC fee is often insufficient to have a transaction included in the next block; it gets outbid by transactions that include higher fees. While even a low fee transaction will probably confirm eventually, it can take a while.

Try increasing the fee

If you want to have your transaction confirmed faster, the obvious solution is to include a higher fee.

If your wallet (by default) includes an insufficient fee, you may be able to adjust the fee manually, either as part of the wallet settings, or when you send a transaction. (Or both.)

Websites like 21.co monitor the network and suggest how much of a fee you should include per byte, as well as how fast you can expect your transactions to confirm at different fee levels.

If you need the payment to go through in the next block or two, you need to pay a higher fee. For less urgent payments, you can include a lower fee; it will just take a bit longer to confirm.

Check if your wallet includes dynamic fees

These days, most wallets support dynamic fees. Based on data from the Bitcoin network, these wallets automatically include a fee that is estimated to have a transaction included in the next block, or maybe in one of the first blocks after that.

Some wallets also let you choose the fee priority. Again, higher fees let your transactions confirm faster, lower fees could make it take a bit longer.

If transactions from your wallet are often delayed during peak hours, and you have no option to adjust to higher priority fees, your wallet is most likely outdated. Check if there is an update available, or switch to a new wallet.

Consider switching wallets

If you do switch to a new wallet, you of course need to transfer funds from your old wallet to your new wallet. If you’re not in a rush and don’t mind paying the fee, you can just send it from your old wallet to the new wallet through the Bitcoin network. It will probably arrive eventually — even if the fee is low.

If you are in a rush, some wallets allow you to export your private keys or the private key seed, and then import them into the new wallet. This requires no transaction on the Bitcoin network. From the new wallet, you can immediately start transacting.

After You’ve Sent It

If you’ve already sent a transaction and it gets stuck, that transaction can, in some cases, be made to “jump the queue.”

The easiest way to make your transaction jump the queue is using an option called Opt-In Replace-by-Fee (Opt-In RBF). This lets you re-send the same transaction, but with a higher fee.

In most cases, when the same transaction is re-sent over the network, but with a higher fee, the new transaction is rejected by the network. Bitcoin nodes typically consider this new transaction a double spend, and will therefore not accept or relay it.

But when sending a transaction using Opt-In RBF, you essentially tell the network you may re-send that same transaction later on, but with a higher fee. As a result, most Bitcoin nodes will accept the new transaction in favor of the older one; allowing the new transaction to jump the queue.

Whether your new transaction will be included in the very next block does depend on which miner mines that next block: not all miners support Opt-In RBF. However, enough miners support the option to, in all likelihood, have your transaction included in one of the next couple blocks.

Opt-In RBF is currently supported by two wallets: Electrum and GreenAddress. Depending on the wallet, you may need to enable Opt-In RBF in the settings menu before you send the (first) transaction.

Child Pays for Parent

If your wallet does not support Opt-In RBF, things get a bit more complex.

Child Pays for Parent (CPFP) may do the trick. Applying CPFP, miners don't necessarily pick the transactions that include the most fees, but instead pick a set of transactions that include most combined fees.

Without getting into too many technical details, most outgoing transactions do not only send bitcoins to the receiver, but they also send “change” back to you. You can spend this change in a next transaction.

Some wallets let you spend this change even while it is still unconfirmed, so you can send this change to yourself in a new transaction. This time, make sure to include a high enough fee to compensate for the original low fee transaction. A miner should pick up the whole set of transactions and confirm them all at once.

If your wallet does not let you select which bitcoins to spend exactly — meaning you cannot specifically spend the unconfirmed change — you can try spending all funds in the wallet to yourself; this should include the change.

Like Opt-In RBF, not all miners currently support CPFP. But enough of them do to probably have your transaction confirmed in one of the next blocks.

If neither Opt-In RBF nor CPFP are an option, you can technically still try and transmit the original transaction with a higher fee. This is typically referred to as “full replace-by-fee,” which some miners accept. However, publicly available wallets currently do not support this as an option.

Otherwise, you may just have to wait either until the transaction confirms or until the bitcoins reappear in your wallet. It’s important to note that until a transaction confirms, the bitcoins are technically still in your wallet — it’s just that it often doesn’t appear that way. The bitcoins are not literally “stuck” on the network and cannot get lost.

Update: Since completion of this article, mining pool ViaBTC started offering a “transaction accelerator”. If your transaction is stuck and includes at least 0.1 mBTC fee per kilobyte, you can submit the transaction-ID to ViaBTC, and the pool will prioritize it over other transactions. Since ViaBTC controls about seven percent of hash-power on the Bitcoin network, there is a good chance it will find a block within a couple of hours. The service is limited to 100 transactions per hour, however.

As the Receiver

Of course, a transaction can also get stuck if you’re on the receiving end of it.

If your wallet allows spending unconfirmed transactions, this can be solved with CPFP as well. Much like as mentioned before, you can re-spend the unconfirmed, incoming bitcoins to yourself, including a fee high enough to compensate for the initial low fee transaction. If the new fee is sufficient, the transaction should typically confirm within a couple of blocks.

The only other option is to ask the sender whether he used Opt-In RBF. If so, he can re-send the transaction with a higher fee.

Update: Of course, ViaBTC’s transaction accelerator (mentioned above) works for incoming transactions as well.

How to read a Bitcoin transaction

Last updated on February 23rd, 2018 at 10:04 am

When you think about it, Bitcoin transactions should be simple: I send money from one Bitcoin address to another. All I need to know is the origin, destination and amount, right? It turns out that Bitcoin transactions are much more complicated than this. We’re going to learn how to read a Bitcoin transaction simply, as well as understand all that gibberish that generally follows.

[tweet_box design=”box_02″]Bitcoin addresses don’t actually exist like you may think they do.[/tweet_box]

The blockchain is not a ledger of all the accounts that exist and their respective balances, but rather a comprehensive history of all Bitcoin transactions. In fact, the entire blockchain is full of transactions and not much else (and a bit of data that connect the blocks).

Bitcoin is a system designed to avoid having to trust account balances (maintained by third parties), and in fact allows everyone to verify and track every single fraction of a coin that ever existed to make sure no one is gaming the system. This can be done by making all transactions public and verifiable.

See, Bitcoins don’t actually move between addresses, they actually exist in virtual vaults with special cryptographic locks. Instead of sending them, you just change the locks. If Alice “owns Bitcoins”, she actually just has a cryptographic key to a vault that has BTC inside. And when Alice wants to send those Bitcoins to Bob, she just unlocks her lock and puts the Bitcoins in a vault with Bob’s lock on it. Now Bob “owns” them.

Vaults and locks are free and easy to make, so if Alice only wants to send some of the coins (and keep the rest), she can create a new vault with her lock and put the change in it. Every time someone opens a lock, the whole network needs to be able to verify it (otherwise they will consider it cheating), so a cryptographic signature is used to prove you have the key to that lock.

Since this is all done digitally, a Bitcoin transaction is simply a record of:

  • Input(s): signature proving you can actually open a locked vault.
  • Output(s): how many Bitcoins are placed in each new vault and with what lock.

Pro tip:
The sum of your outputs cannot be higher than the sum of your inputs (otherwise you’re making Bitcoins out of thin air), but it can be lower. The difference in the sum of inputs and outputs equals to the miner fee. This means that you will never see any reference to miner’s fees in a transaction, rather you simply infer it: one BTC inputs – 0.9 BTC outputs = 0.1 BTC miner fee. Bitcoin wallets manage this automatically for you.

So what does a Bitcoin transaction actually look like?

“Raw” Bitcoin transactions are actually very difficult to read, which is why there is a plethora of “block explorers”, which are websites or other software used to “translate” and more easily read what’s going on in the blockchain. For this example, we will look at Blocktrail, but you can really use any of many (and trust me, there are many).

Blocktrail, like many block explorers, will show more information about the transaction than the transaction itself: things like when it was first seen, how long it took to confirm; other explorers will tell you how much money was “sent” and how much was “change”, etc. Most of this extra information is useful, but it is also mostly guessing. Only the transaction itself in the blockchain can be verified cryptographically.

The following transaction (following the convention of being named after the “hash” of the transaction itself: 61a1..0b0c) is a pretty simple and common transaction: it collects BTC from two different inputs (previous transactions) for a total of 159 bits and then sends them to two different outputs for a total of 59 bits. Note that there are 100 bits leftover, which were never used in the transaction outputs: they were leftover for miner fees.

The basics: inputs, outputs and values

These are the most important parts of the transaction page, they tell us where the money is coming from and where it’s going. Let’s say we want to confirm receiving a Bitcoin payment (let’s say 50 bits to the address 1AFc…7VeQ), so we’ll look for our address in the list of outputs, and confirm that the correct amount of coins were sent there. In this case, we see that the transaction indeed includes our payment.

The other output (which sends nine bits to 3GmY…6J4S) is probably their change address, but that’s extrapolation, and honestly not much of our business. We can follow each address by clicking on it, or follow each input/output by clicking the arrow next to it. The ‘P2SH’ label means that the address (the lock on the vault) is a script hash, which means that the address allows for the recipient to use more complex signatures (such as multisig).

More information

The information above the inputs and outputs could be of use, such as when Blocktrail first saw the transaction (“Relay time”), as well as how long it took until it was confirmed in a block (“Time until confirmed”). Of course, it will show us in which block it was confirmed (“Block”), as well as how many confirmations it has (“Confirmations”). The “Priority” is Blocktrail’s way of calculating how good the fees are on this transaction (based on coin age and transaction size in bytes).

Raw information

The real, hard information about the transaction is actually listed in the scripts on the bottom: that’s the “raw” information about each of the inputs and outputs. The output script includes the cryptographic lock and vault that you’re sending the Bitcoins to. The input script includes the signature proving that the owner of the vault can open the lock determined by the previous output (from the previous transaction).

If you’re interested in learning more in depth about Bitcoin transactions, I highly recommend browsing through the Transactions chapter in Mastering Bitcoin by Andreas Antonopoulos.

How Do Bitcoin Transactions Actually Work?

Whether you’re interested in becoming a developer for blockchain applications, or you’re just looking to understand what happens under the hood when you send bitcoin to a friend, it’s good to have a working knowledge of what happens when you create and broadcast Bitcoin transactions to the Bitcoin network. Why?

Because transactions are a basic entity on top of which the bitcoin blockchain is constructed. Transactions are the result of a brilliant collision of cryptography, data structures, and simple non-turing-complete scripting. They’re simple enough that common transaction types aren’t overly-complex, but flexible enough to allow developers to encode fairly customized transactions types as well. Today we’ll take a tour of the former.

As a developer, how does your bitcoin client post a new transaction to the network (and what happens when it’s received)?

What exactly is happening when you send some bitcoin to a friend?

This post will assume that the reader has a basic understanding of hashing, asymmetric cryptography, and P2P networking. It’s also a good idea to have a good sense for what exactly a blockchain is, even if you’re unfamiliar with any specific mechanics.

Bitcoin Transactions and their role in the bigger picture

Bitcoin is comprised of a few major pieces: nodes and a blockchain. The role of a typical node is to maintain its own blockchain version and update it once it hears of a “better” (longer) version. Simply put, the blockchain has blocks, and blocks have transactions.

With this simplified but accurate picture in mind, you might be wondering what exactly a transaction is made out of.

  • How will understanding transactions help me to become a better blockchain developer?
  • How do transactions allow me to transfer some bitcoin to a friend?

It turns out that the answers to these questions vary based on many things. Even assuming that we’re talking only bitcoin, we can use transactions in a number of creative ways to accomplish a variety of personalized goals. Let’s start at the beginning, that is, let’s take a look a good old-fashioned pay-to-PK-hash transaction type. After all, this type of transaction accounts for over 99% of all transactions on the bitcoin blockchain.

First, let’s build a mental model. It’s tempting to think of bitcoin as an account-based system. After all, when I send bitcoin to somebody, that person receives money and I’m left with a remaining balance. In the real world though, things are represented a bit differently. Generally speaking, when I send money to somebody I am sending spending all of that money (minus transaction fees). Some of that money will be spent back to my own personal account if there exists a remaining balance. The point is that all of the money moves every single time. You can skip to section 3.1 of for an explanation of why this model is preferable.

With that in mind, we can generalize and say that a bitcoin transaction has some inputs and outputs. A graphical representation might look something like this:

This was somewhat confusing to me when I first saw it, so I’ll elaborate a bit. When I post a transaction, I’m essentially “claiming” an output and proving that I have permission to spend the amount of money at that output. So if I’m Bob and I want to pay Alice, those inputs are my proof that I have been given a certain amount of money (although this might just be a portion of my total balance), and the outputs will correspond to Alice’s account. In this simple case, there would be only a single input and a single output.

A deeper look into Bitcoin transactions

Let’s understand the mechanics of a real bitcoin transaction. We’ll use the image above as a reference.

If you were to cut open a typical bitcoin transaction, you’d end up with three major pieces: the header, the input(s), and the output(s). Let’s briefly look at the fields available to us in these sections, as they’ll be important for discussion. Note that these are the fields that are in a so-called raw transaction. Raw transactions are broadcast between peers when a transaction is created.

The Header

  • hash: The hash over this entire transaction. Bitcoin generally uses hash values both a pointer and a means to check the integrity of a piece of data. We’ll look at this more in the next section.
  • ver: The version number that should be used to verify this block. The latest version was introduced in a soft fork that became active in December 2015.
  • vin_sz: The number of inputs to this transaction. Similarly, vout_sz counts the number of outputs.
  • lock_time: We’ll look at this more in later articles, but this basically describes the earliest time at which a block can be added to the blockchain. It is either the block height or a unix timestamp.

Input

  • previous output hash: This is a hash pointer to a previously unspent transaction output (UTXO). Essentially, this is money that belongs to you that you are about to spend in this transaction.
  • n: An index into the list of outputs of the previous transaction. This is the actual output that you are spending.
  • scriptSig: This is a spending script that proves that the creator of this transaction has permission to spend the money referenced by 1. and 2.

Output

  • value: The amount of Satoshi being spent (1 BTC = 100,000,000 Satoshi).
  • scriptPubKey: The second of two scripts provided in a bitcoin transaction, which points to a recipient’s hashed public key. More on this in the last section of this article.

Transaction verification

One of the jobs of a bitcoin node is the verify that incoming transactions are correct (data hasn’t been tampered with, money isn’t being created, only intended recipients spend UTXOs, etc). A more exhaustive list can be found online, but I’ll list out a few of the important ones here:

  • All outputs claimed by inputs of this transaction are in the UTXO pool. Unspent outputs can only ever be claimed once.
  • The signatures on each input are valid. More precisely, we’re saying that the combined scripts return true after executing them one after the other. More on this in the last section.
  • No UTXO is spent more than once by this transaction. Notice how this is different than the first item.
  • All of the transaction’s output values are non-negative.
  • The sum of this transaction’s input values is greater than the sum of its output values. Note that if the numbers are different, the difference is considered to be a transaction fee that can be claimed by the miner.

A basic pay-to-PK-hash transaction

Bitcoin has its own custom (Forth-like) scripting language that is powerful enough to allow developers to create complicated and custom types of transactions. There are five or so standard transaction types that are accepted by standard bitcoin clients [5], however, there exist other clients that will accept other types of transactions for a fee. We’ll just cover the mechanics of pay-to-PK-hash here.

For any transaction to be valid, a combined scriptSig/scriptPubKey pair must evaluate to true. More specifically, a transaction spender provides a scriptSig that is executed and followed by the scriptPubKey of the claimed transaction output (remember how we said inputs claim previous unspent transaction outputs?). Both scripts share the same stack.

In the interest of efficiency, let’s use (official bitcoin wiki) a reference as we discuss. When you visit the link, go about halfway down to find a table containing 7 rows. This table shows how the scripts are combined, how execution occurs, and what the stack looks like at each step.

One thing to note is that, because bitcoin addresses are actually hashes (well, it gets even a bit more complicated. See ), there is no way for the sender to know the actual public key to check against the private key. Therefore, the Redeemer specifies both the public key and private key, and the scriptPubKey will duplicate and hash the public key to make sure that the Redeemer is indeed the intended recipient.

During execution, you can see that constants are placed directly onto the stack when they are encountered. Operations add or remove items from the stack as they are evaluated. For example, OP_HASH160 will take the top item from the stack, and has it twice, first with SHA-256 and then with RIPEMD-160. When all items in our script have been evaluated, our entire script will evaluate to true if true remains on the stack, and false otherwise.

All in all, the pay-to-PK-hash is a pretty straightforward transaction type. It ensures that only a redeemer with the appropriate public/private key pair can claim and subsequently spend bitcoin. Assuming that all other criteria are met (see the previous section), then the transaction is a good one and it can be placed into a block.

In future articles, I’ll break down more complicated types of transactions. We’ll see how more than two parties can participate in a transaction, and we’ll see how longer-running transaction types can be implemented.

Transaction

A transaction is a transfer of Bitcoin value that is broadcast to the network and collected into blocks. A transaction typically references previous transaction outputs as new transaction inputs and dedicates all input Bitcoin values to new outputs. Transactions are not encrypted, so it is possible to browse and view every transaction ever collected into a block. Once transactions are buried under enough confirmations they can be considered irreversible.

Standard transaction outputs nominate addresses, and the redemption of any future inputs requires a relevant signature.

All transactions are visible in the block chain, and can be viewed with a hex editor. A block chain browser is a site where every transaction included within the block chain can be viewed in human-readable terms. This is useful for seeing the technical details of transactions in action and for verifying payments.

What to Do if Your Bitcoin Transaction Gets "Stuck"

The number of transactions on the Bitcoin network has steadily increased over the years. This means more blocks are filling up. And as not all transactions can be included in the blockchain straight away, backlogs form in miners’ “mempools” (a sort of “transaction queue.”)

Miners typically pick the transactions that pay the most fees and include these in their blocks first. Transactions that include lower fees are “outbid” on the so called “fee market,” and remain in miners’ mempools until a new block is found. If the transaction is outbid again, it has to wait until the next block.

This can lead to a suboptimal user experience. Transactions with too low a fee can take hours or even days to confirm, and sometimes never confirm at all.

But here is what you can do today to keep your own transaction from getting stuck.

Before You Send It

For the first years of Bitcoin’s existence, most wallets added fixed fees to outgoing transactions: typically, 0.1 mBTC. Since miners had spare space in their blocks anyways, they normally included these transactions in the first block they mined. (In fact, transactions with lower fees or even no fee at all were often included as well.)

With the increased competition for block space, a fixed 0.1 mBTC fee is often insufficient to have a transaction included in the next block; it gets outbid by transactions that include higher fees. While even a low fee transaction will probably confirm eventually, it can take a while.

Try increasing the fee

If you want to have your transaction confirmed faster, the obvious solution is to include a higher fee.

If your wallet (by default) includes an insufficient fee, you may be able to adjust the fee manually, either as part of the wallet settings, or when you send a transaction. (Or both.)

Websites like 21.co monitor the network and suggest how much of a fee you should include per byte, as well as how fast you can expect your transactions to confirm at different fee levels.

If you need the payment to go through in the next block or two, you need to pay a higher fee. For less urgent payments, you can include a lower fee; it will just take a bit longer to confirm.

Check if your wallet includes dynamic fees

These days, most wallets support dynamic fees. Based on data from the Bitcoin network, these wallets automatically include a fee that is estimated to have a transaction included in the next block, or maybe in one of the first blocks after that.

Some wallets also let you choose the fee priority. Again, higher fees let your transactions confirm faster, lower fees could make it take a bit longer.

If transactions from your wallet are often delayed during peak hours, and you have no option to adjust to higher priority fees, your wallet is most likely outdated. Check if there is an update available, or switch to a new wallet.

Consider switching wallets

If you do switch to a new wallet, you of course need to transfer funds from your old wallet to your new wallet. If you’re not in a rush and don’t mind paying the fee, you can just send it from your old wallet to the new wallet through the Bitcoin network. It will probably arrive eventually — even if the fee is low.

If you are in a rush, some wallets allow you to export your private keys or the private key seed, and then import them into the new wallet. This requires no transaction on the Bitcoin network. From the new wallet, you can immediately start transacting.

After You’ve Sent It

If you’ve already sent a transaction and it gets stuck, that transaction can, in some cases, be made to “jump the queue.”

The easiest way to make your transaction jump the queue is using an option called Opt-In Replace-by-Fee (Opt-In RBF). This lets you re-send the same transaction, but with a higher fee.

In most cases, when the same transaction is re-sent over the network, but with a higher fee, the new transaction is rejected by the network. Bitcoin nodes typically consider this new transaction a double spend, and will therefore not accept or relay it.

But when sending a transaction using Opt-In RBF, you essentially tell the network you may re-send that same transaction later on, but with a higher fee. As a result, most Bitcoin nodes will accept the new transaction in favor of the older one; allowing the new transaction to jump the queue.

Whether your new transaction will be included in the very next block does depend on which miner mines that next block: not all miners support Opt-In RBF. However, enough miners support the option to, in all likelihood, have your transaction included in one of the next couple blocks.

Opt-In RBF is currently supported by two wallets: Electrum and GreenAddress. Depending on the wallet, you may need to enable Opt-In RBF in the settings menu before you send the (first) transaction.

Child Pays for Parent

If your wallet does not support Opt-In RBF, things get a bit more complex.

Child Pays for Parent (CPFP) may do the trick. Applying CPFP, miners don't necessarily pick the transactions that include the most fees, but instead pick a set of transactions that include most combined fees.

Without getting into too many technical details, most outgoing transactions do not only send bitcoins to the receiver, but they also send “change” back to you. You can spend this change in a next transaction.

Some wallets let you spend this change even while it is still unconfirmed, so you can send this change to yourself in a new transaction. This time, make sure to include a high enough fee to compensate for the original low fee transaction. A miner should pick up the whole set of transactions and confirm them all at once.

If your wallet does not let you select which bitcoins to spend exactly — meaning you cannot specifically spend the unconfirmed change — you can try spending all funds in the wallet to yourself; this should include the change.

Like Opt-In RBF, not all miners currently support CPFP. But enough of them do to probably have your transaction confirmed in one of the next blocks.

If neither Opt-In RBF nor CPFP are an option, you can technically still try and transmit the original transaction with a higher fee. This is typically referred to as “full replace-by-fee,” which some miners accept. However, publicly available wallets currently do not support this as an option.

Otherwise, you may just have to wait either until the transaction confirms or until the bitcoins reappear in your wallet. It’s important to note that until a transaction confirms, the bitcoins are technically still in your wallet — it’s just that it often doesn’t appear that way. The bitcoins are not literally “stuck” on the network and cannot get lost.

Update: Since completion of this article, mining pool ViaBTC started offering a “transaction accelerator”. If your transaction is stuck and includes at least 0.1 mBTC fee per kilobyte, you can submit the transaction-ID to ViaBTC, and the pool will prioritize it over other transactions. Since ViaBTC controls about seven percent of hash-power on the Bitcoin network, there is a good chance it will find a block within a couple of hours. The service is limited to 100 transactions per hour, however.

As the Receiver

Of course, a transaction can also get stuck if you’re on the receiving end of it.

If your wallet allows spending unconfirmed transactions, this can be solved with CPFP as well. Much like as mentioned before, you can re-spend the unconfirmed, incoming bitcoins to yourself, including a fee high enough to compensate for the initial low fee transaction. If the new fee is sufficient, the transaction should typically confirm within a couple of blocks.

The only other option is to ask the sender whether he used Opt-In RBF. If so, he can re-send the transaction with a higher fee.

Update: Of course, ViaBTC’s transaction accelerator (mentioned above) works for incoming transactions as well.

How does Bitcoin work?

This is a question that often causes confusion. Here's a quick explanation!

The basics for a new user

As a new user, you can get started with Bitcoin without understanding the technical details. Once you have installed a Bitcoin wallet on your computer or mobile phone, it will generate your first Bitcoin address and you can create more whenever you need one. You can disclose your addresses to your friends so that they can pay you or vice versa. In fact, this is pretty similar to how email works, except that Bitcoin addresses should only be used once.


Balances - block chain

The block chain is a shared public ledger on which the entire Bitcoin network relies. All confirmed transactions are included in the block chain. This way, Bitcoin wallets can calculate their spendable balance and new transactions can be verified to be spending bitcoins that are actually owned by the spender. The integrity and the chronological order of the block chain are enforced with cryptography.

Transactions - private keys

A transaction is a transfer of value between Bitcoin wallets that gets included in the block chain. Bitcoin wallets keep a secret piece of data called a private key or seed, which is used to sign transactions, providing a mathematical proof that they have come from the owner of the wallet. The signature also prevents the transaction from being altered by anybody once it has been issued. All transactions are broadcast between users and usually begin to be confirmed by the network in the following 10 minutes, through a process called mining.

Processing - mining

Mining is a distributed consensus system that is used to confirm waiting transactions by including them in the block chain. It enforces a chronological order in the block chain, protects the neutrality of the network, and allows different computers to agree on the state of the system. To be confirmed, transactions must be packed in a block that fits very strict cryptographic rules that will be verified by the network. These rules prevent previous blocks from being modified because doing so would invalidate all following blocks. Mining also creates the equivalent of a competitive lottery that prevents any individual from easily adding new blocks consecutively in the block chain. This way, no individuals can control what is included in the block chain or replace parts of the block chain to roll back their own spends.

Going down the rabbit hole

This is only a very short and concise summary of the system. If you want to get into the details, you can read the original paper that describes the system's design, read the developer documentation, and explore the Bitcoin wiki.

How a Bitcoin Transaction Works

This article explains what a Bitcoin transaction is, its purpose and outcome. The explanation made below is suitable for both novice and intermediate Bitcoin users.

As a cryptocurrency user you need to be familiar with transaction rudiments – for the sake of your own confidence with this evolving innovation, and as a foundation for understanding emerging multi-signature transactions and contracts, both of which will be explored later in the series. This is not a technical article and explanation will focus on what you need to know about standard bitcoin transactions – the spend transactions we commonly make – and we’ll gloss over what you can safely ignore.

An infographic at the bottom of the article provides a comprehensive illustration of the entire Bitcoin transaction process from wallet to blockchain.

Note: Even the Core developers acknowledge that some of the language being used to describe transactions and their components can lead one to a mistaken concept of what is really happening. These misconceptions are avoided in the explanation below. So, while trying to keep things as simple as possible, and with the aid of a few diagrams, let’s dive right in.

Definition of Terms and Abbreviations

Bitcoin with a capital “B” refers to the protocol – the code, the nodes, the network and their peer-to-peer interaction.
bitcoin with a lowercase ‘b’ refers to the currency – the cryptocurrency we send and receive, via the Bitcoin network.
tx – wherever it is used in the text – is an abbreviation for ‘Bitcoin transaction‘
txid is an abbreviation for ‘transaction id’ – this is a hash that is used by both humans and the protocol to reference transactions.
Script is the name of the Bitcoin protocol’s scripting system that processes and validates transactions. Script is a clever, stack-based instruction engine, and it makes all transactions from simple payments to complex oracle overseen contracts possible.
UTXO is an abbreviation for Unspent Transaction Output, also referred to as an “output”.
satoshi – 1 BTC = 100,000,000 satoshi

What is a Bitcoin Transaction and Why?

Definition

A Bitcoin transaction is a signed piece of data that is broadcast to the network and, if valid, ends up in a block in the blockchain.

The purpose of a Bitcoin transaction is to transfer ownership of an amount of Bitcoin to a Bitcoin address.

When you send Bitcoin, a single data structure, namely a Bitcoin transaction, is created by your wallet client and then broadcast to the network. Bitcoin nodes on the network will relay and rebroadcast the transaction, and if the transaction is valid, nodes will include it in the block they are mining. Usually, within 10-20mins, the transaction will be included, along with other transactions, in a block in the blockchain. At this point the receiver is able to see the transaction amount in their wallet.

Here is an example transaction that was included in the blockchain earlier this year:

The main components of this standard transaction are color-coded:

  • Transaction ID(highlighted in yellow)
  • Descriptors and meta-data(blue curly brace elaborated upon to the right)
  • Inputs(pink area)
  • Outputs(green area)

Bitcoin Transaction Inputs and Outputs

Firstly, four axiomatic truths about transactions:

  • Any Bitcoin amount that we send is always sent to an address.
  • Any Bitcoin amount we receive is locked to the receiving address – which is (usually) associated with our wallet.
  • Any time we spend Bitcoin, the amount we spend will always come from funds previously received and currently present in our wallet.
  • Addresses receive Bitcoin, but they do not send Bitcoin – Bitcoin is sent from a wallet.

The amounts that go into our wallet are not jumbled like the coins in a physical wallet. The received amounts don’t mix but remain separate and distinct as the exact amounts received by the wallet. Here’s an illustration:

You create a brand new wallet and, in time, it receives three amounts of 0.01, 0.2 and 3 BTC as follows: you send 3 BTC to an address associated with the wallet and two payments are made to another address by Alice.

The wallet reports a balance of 3.21 BTC, yet if you were to virtually peek inside the wallet, you would see – not 321,000,000 satoshi (321 mil satoshi) – but three distinct amounts still grouped together by their originating transactions: 0.01, 0.2 and 3 BTC.

The received bitcoin amounts don’t mix but remain separated as the exact amounts sent to the wallet. The three amounts in the example above are called the outputs of their originating transactions.

Bitcoin wallets always keep outputs separate and distinct.

Definition

An output is an amount that was sent (via a standard transaction) to a Bitcoin address, along with a set of rules to unlock the output amount. In Bitcoin parlance an output is called an “unspent transaction output”, or UTXO.

A standard transaction output can be unlocked with the private key associated with the receiving address. Addresses and their associated public/private key pairs will be covered later in the series. For now, we are concerned with the output amount only.

Let’s consider an example by following the money in a scenario where you send 0.15 BTC to Bob.

As we have seen, your wallet does not select 15 mil satoshi (0.15 BTC) from an undifferentiated pool of 321 mil satoshi making up the wallet balance. Instead, the wallet selects a spend candidate from amongst the three existing “outputs” contained in the wallet. So, it chooses (for various reasons that are not important now) the 0.2 BTC output. The wallet will unlock the 0.2 BTC output and use the whole amount of 0.2 BTC as an input to your new 0.15 BTC transaction. The 0.2 BTC output is “spent” in the process. –Read this paragraph a second time.

The spend transaction your wallet creates will send 0.15 BTC to Bob’s address – where it will reside in his wallet as an output – waiting eventually to be spent.

The 0.05 BTC difference (0.2 BTC input minus 0.15 BTC output) is called “change” and the transaction will send this back to your wallet via a newly created address. The 0.05 BTC change amount will reside in your wallet as a new output – waiting eventually to be spent. So, now, a virtual peek inside your wallet reveals the following:

Each of the three outputs that are “waiting to be spent”, is locked to its receiving addresses until such time as one or more of them are selected as input(s) to a new spend transaction.

Behind the scenes, different wallet clients apply different logic rules when selecting UTXOs as inputs to new transactions. A sane wallet policy is to use older UTXOs first, wherever possible, but implementations differ. The manner in which UTXOs are selected is not of concern to us right now, since the objective has been emphasis of the point that amounts received to our wallets remain separate and distinct.

Summary of How a Bitcoin Transaction Works

Various received amounts don’t mix as they do in a physical wallet. Instead, received amounts (UTXOs) are used individually (or in combination) at the moment we spend Bitcoin. When creating the spend transaction our wallet selects UTXOs (of sufficient value to satisfy the amount we want to send) and typically creates two new outputs: one for the receiver and one for the change we receive back to our wallet. The change becomes a brand new UTXO in our wallet, and the amount we send becomes a UTXO locked to the recipient address – which may or may not be associated with a wallet, e.g. cold storage. The original UTXO used as input to the spend transaction is “spent” and destroyed forever.

This has been an introduction to how outputs (UTXOs) are handled by wallet software. Once a UTXO is selected for expenditure, it requires the private key associated with the address that received it. This private key redeems the UTXO and allows it to become an input in a new spend transaction. The mechanism whereby previous transaction outputs are reused as the inputs to new transactions is central to the Bitcoin protocol’s function – and exactly as per Satoshi’s design.

How to cancel an unconfirmed Bitcoin transaction

Once confirmed, Bitcoin transactions are irreversible and you are unable to cancel them.

To cancel an unconfirmed bitcoin transaction, you need to use a Replace by Fee (RBF) protocol to replace your original transaction with a new one using a higher transaction fee. If you aren't able to use RBF, you may be able to cancel your transaction by double spending using a higher fee.

No, you cannot cancel a confirmed Bitcoin transaction.

How to cancel an unconfirmed Bitcoin transaction

When sending Bitcoin, it can be easy to make a small mistake causing you to want to cancel your Bitcoin transaction. Oftentimes, funds can become stuck if the miner fee you enter isn’t high enough for any miner to confirm your transaction.

Unfortunately, the steps to cancel a Bitcoin transaction are a little more complicated than just pressing an “Undo” button. In this brief guide, I’ll walk you through the process to cancel an unconfirmed Bitcoin transaction.

Has your transaction been confirmed?

The first step in canceling your Bitcoin transaction is to check whether or not it has any confirmations.

When you made your transaction, you should have gotten a transaction ID that looks something like this:

240615b6ab59a5adb19ba52cb969aeb16ff82d2082b7a72cb2912c5d38c297cf

Take your transaction ID and enter it into a block explorer. Blockchain.info is a great option.

On the next page, you can see information about your transaction including the number of its confirmations.

If the number of confirmations is greater than 0, you won’t be able to cancel your transaction. Confirmed transactions on the blockchain are permanent and irreversible. Just wait and your transaction will finish going through soon.

If the transaction has no confirmations yet, there’s still a chance that you can cancel it.

How to cancel an unconfirmed Bitcoin transaction

There are two primary strategies you can use to try to cancel your unconfirmed Bitcoin transaction:

  1. Replace by Fee (RBF)
  2. Double spend using a higher fee

Some wallets support the RBF protocol allowing you to replace your original transaction with a new one that includes a higher transaction fee. This would effectively unstick your transaction.

To use this feature, though, you would’ve needed to make the original transaction replaceable (usually via an opt-in checkbox).

If you’re unable to use RBF, you still may be able to cancel the Bitcoin transaction by double spending with a higher fee .

To do this, make a new transaction equal to the amount of the original one and send it to yourself. Make sure the transaction fee on this is significantly higher than the original one you paid.

You may need to use another wallet or specialized software that allows double spending for the transaction to be broadcast to the network.

If all goes well, miners will pick up the new transaction, and your Bitcoin will be back in your wallet.

Most miners and wallets have safeguards against double spending, though, so there’s still a large chance that this method may not work.

Hopefully, one of these two methods works for you. If not, treat this as an important lesson taught to you by the wild world of Bitcoin.

Комментариев нет:

Отправить комментарий

Related Posts Plugin for WordPress, Blogger...