Back

[**] - bitcoin 中的转账和零钱详解

发布时间: 2018-12-15 03:16:00

最初,我发现转账的时候, 不是从A地址转账到B地址, 而是 

A  -> B    0.3

A ->  C   0.8   (这个就很奇怪)

我把帖子发在了:  https://bitcoin.stackexchange.com/questions/81916/what-is-the-actual-second-receiver-address-after-called-sendtoaddress-rpc-comm?noredirect=1#comment95244_81916

然后,人家提醒我, 参考: https://bitcoin.stackexchange.com/questions/736/how-does-change-work-in-a-bitcoin-transaction

说的很明白了. 

1. btc中的address只负责 收款, 

2. address 跟付款没有关系. account/wallet才有关系

3. 比特币有个 "找零"机制, 一个例子: 爸爸给了我一张百元大钞, 我要买一个20块的面包的话, 需要给对方这张大钞,对方再找回我80 . 

所以,  过程就是: 

A -> B  (20)

A -> C  (80)   这个就是找零的过程  ( change) 

这个C地址,就是专门存放零钱的地址.  是临时产生的,  是不会被钱包特意显示出来的. 但是它是确实存在的 . 

4. 比特币本身是一个  伪匿名的 机制 , 所以一个最佳实践是: 一个地址不要重复使用. 

总之, 比特币中的 address, account  跟 eth中的差异巨大

First, let's clarify the difference between accounts and addresses.

"Accounts" are used for the convenience of people to track their funds. This is primarily used to track the source of funds. Since this is just for your tracking, you can move Bitcoins from one account to another just by moving a number from one column to another. No transactions are needed. (This is like when you know you owe your son $25 for allowance, and you have $200 budgeted for groceries.)

"Addresses" are used to receive Bitcoins in transactions. The coins are sent to an address. The client associates each address with an account and adds received funds to that account. This is simply done for convenience to allow people to track indirectly which address funds were sent to. But you can have any number of addresses associated with the same account.

Change comes from the way Bitcoins are spent. To spend a certain number of Bitcoins, you must pull in Bitcoins from transaction outputs to accounts you control. Note that in the spending part, it doesn't matter what address this is or what account that address is associated with. When you spend Bitcoins from a particular account, that just means you debit that account for the amount you send. It doesn't mean the funds come from addresses associated with that account. Remember, the association between addresses and accounts is for receiving only, not sending. (Like when you spend money on groceries, it's not like you have specific bills for groceries. You just have an amount budgeted.)

So when you pull in transaction outputs, you form a pile of Bitcoins big enough for the number you are trying to send. Usually, it won't be exact since you must claim an entire output. So the excess forms the 'change'.

Since there is no address associated with sending Bitcoins, there is no particular address the change should be sent to. So, to preserve anonymity, the client creates a new one just to receive the change from this transaction. Since this address isn't really associated with an account and shouldn't be used to receive any more Bitcoins (because that would senselessly tell people the same recipient got the coins as got this change) the client does not display it.

Because the client manages coins in a particular way, it doesn't make sense to try to view coins it is managing with any kind of explorer. It's specifically trying to obscure the fact that all the coins are related. Those kinds of services are intended to monitor recieved funds, not managed funds.

第二个答案:

The information in David's answer is correct, but it may not answer the actual question -- it's unclear whether the question is about change in general, or specifically sending change to a new address.

If the latter, nothing needs to be added. If, however, the question was about the practice of change in general, then yes, it is necessary.

The reason for this is that an output, when used as an input, must be spent in its entirety. Say someone sends you 10 BTC, that 10 BTC is a single output. You cannot spend part of that coin, the same way you couldn't slice off a part of a physical coin and have it maintain its value.

The reason for this is that an output is actually a script, and to spend an output you simply broadcast the solution to this script. That output, in its entirety, becomes an input -- and if you were to not include change, the difference between the inputs and outputs would all go to transaction fees.

What is client-specific is how to handle this change: the Satoshi client sends it to a new address, while other clients may simply send the change back to one of the output addresses.

The change is an output like any other, which means that you do need to wait for confirmations -- but you can still use that change to send another transaction immediately, you'll just need to wait for the first transaction to confirm before the second one can.

第三个答案:

Does it have it have to work like this, or is this a specific implementation detail of the client software?

Yes, this is implemented by the Bitcoin protocol itself, but it's only best practice not to re-use addresses. Since we are dealing with a pseudo-anonymous cryptocurrency would make sense to increase "anonimity" the more we can do.
You can however force your wallet to send "change" to a static and permanent address without generating a new change address each time you make a transaction. This will reduce substancially your privacy and transactions history will not be "obfuscated" as it is intended to be.

Also, do you have to wait for change to be confirmed before you can spend it again?

No, you can spend the change coins with 0 confirmations also.

Except coinbase coins (i.e. fresh mined coins which needs 100 blocks to mature) you can spend coin with 0 confirmations from command line wallets and many others. This is permitted by the protocol itself but many clients may not allow users to broadcast txs until the inputs has 1 confirmation at least, or even more.

REMEMBER that spending 0 confirmations coins from untrusted source can result in transaction pruning from the network mempool due to possible "pseudo-double spending" attack. In the case of spending your own change with 0 confirmations you are trusting yourself as the original sender so this is not a problem (unless also the original transaction which generated the "change" coins was with 0 confirmations from an untrusted sender.)

Back