0

I was playing around with my Bitcoin Node, to try and understand how does Bitcoin Transactions work.

For this purpose, I used the sendtoaddress API call for bitcoin-cli, to send some XBT to my own Bitcoin Blockchain.Info wallet. The transaction was processed, and I was trying to understand the information that I get from gettransaction bitcoin-cli command, and the information that the Blockchain.info website shows about the transaction.

So, here is what I did:

  1. I've generated a receiving address for myself in Blockchain.Info (17tzZwAi722L7V8V27bUGEKwJpRYVNRKVW)

  2. In my Bitcoin node, I used the following command: bitcoin-cli sendtoaddress 17tzZwAi722L7V8V27bUGEKwJpRYVNRKVW 0.001

This gave me back a transaction id: 4f299e7313af7e4e091ea519bbf5983526d18fe4765b679ce1827bd9f75dbaff

  1. I then checked the information that the bitcoin node gives about that transaction with: bitcoin-cli gettransaction 4f299e7313af7e4e091ea519bbf5983526d18fe4765b679ce1827bd9f75dbaff

What I noticed here is that the bitcoin-cli command gave me back the address I sent the money to, the fee it took to get the address, but it didn't tell me from which address the transaction was sent from.

Then I checked the information that Blockchain.info provides about the transaction: https://blockchain.info/tx/4f299e7313af7e4e091ea519bbf5983526d18fe4765b679ce1827bd9f75dbaff

Here, it can be clearly seen that an amount of 0.06611392 BTC was sent from 12bFMAPz7dhKmLxsoipfUqmCCjqENCDzKb XBT address, to two different outputs. One of the output is the address, Blockchain.Info gave me to receive the Bitcoin. The other output is an address unknown to me.

So I started thinking: Am I correct, that when sending a bitcoin transaction, all of the amount from a specific address gets placed in the input, a part of it(the part which I specify) gets sent to the address I wish to send, and the rest gets transfered to a newly created address on the same wallet, from which the send operation was initiated?

Some other questions which arise to me: How is Blockchain.Info able to retrieve information from any kind of Bitcoin Transaction, while I, using a full Bitcoin Node, can only find transactions which was either initiated by the node, or which has a receiving address which is in the nodes wallet?

2 Answers 2

1

but it didn't tell me from which address the transaction was sent from

Indeed, there is no 'from address' in a bitcoin transaction. (More info)

Am I correct, that when sending a bitcoin transaction, all of the amount from a specific address gets placed in the input, a part of it(the part which I specify) gets sent to the address I wish to send, and the rest gets transfered to a newly created address on the same wallet, from which the send operation was initiated?

Correct, inputs are spent all at once, there's no way to partially spend it, so you have to send some change back to yourself. The sendtoaddress manages that all for you.

How is Blockchain.Info able to retrieve information from any kind of Bitcoin Transaction, while I, using a full Bitcoin Node, can only find transactions which was either initiated by the node, or which has a receiving address which is in the nodes wallet?

That's a lot of data that bitcoin core doesn't usually need or use, so it's not usually indexed or accessible by bitcoin core. It's possible to use the -txindex configuration option to index all transactions including those not related to your wallet. But blockchain.info and similar block explorers probably run their own databases of information rather than querying it from a bitcoin node every time, allowing them to do more complicated searches in the data.

0

How is Blockchain.Info able to retrieve information from any kind of Bitcoin Transaction...

It is not only blockchain.info who can decompose your transaction. The format of a transaction is layed out on bitcoin.org. So if you take your own transaction, you as well can decompose it into it's pieces. You can have a look at the details of your (or any other) tx with

https://blockchain.info/rawtx/

I just did the same with "my" local tools, and got this from the script sig:

 TX_IN[0] Script Sig (uchar[])
  4730440220415AE7C712D07CD1F0A98170021FBE3A073DECB569A66F63B28FD2725471EE57022061FE1093885C39D23E1EFE19700D1B8E49619DF526AD0D63CDBF985E2178C34C0121025AB144C5BDD83410487BF2694CA398E3D860D2465E0305DCEC429BA6F1CF8C59 
  ##################################################################
  ### tcls_in_sig_script.sh: decode SIG_script OPCODES from a TX ###
  ##################################################################
    47: OP_DATA_0x47:     push hex 47 (decimal 71) bytes as data
    30: OP_SEQUENCE_0x30: type tag indicating SEQUENCE, begin sigscript
    44: OP_LENGTH_0x44:   length of R + S
    02: OP_INT_0x02:      type tag indicating INTEGER
    20: OP_LENGTH_0x20:   this is SIG R
        415AE7C712D07CD1:F0A98170021FBE3A
        073DECB569A66F63:B28FD2725471EE57
    02: OP_S_INT_0x02
    20: OP_LENGTH_0x20:   this is SIG S
        61FE1093885C39D2:3E1EFE19700D1B8E
        49619DF526AD0D63:CDBF985E2178C34C
    01: OP_SIGHASHALL:    this terminates the ECDSA signature (ASN1-DER structure)
    #########################################################
    ### procedure to strictly check DER-encoded signature ###
    #########################################################
    Minimum and maximum size constraints                        - ok
    scriptsig always starts with 0x30                           - ok
    length 136 chars is less than actual sig length (142 chars) - ok
           (hex 0x44, decimal 68, 136 chars)
    length of R coordinate (64) >= 0                            - ok
    length of S coordinate (64) >= 0                            - ok
    S-Value is within scriptsig boundaries                      - ok
    Make sure the R & S length covers the entire signature      - ok
    S-value must be smaller than N/2                            - ok
    strictly check DER-encoded signature                        - ok
    #########################################################
    21: OP_DATA_0x21:     type tag indicating LENGTH
    02: OP_INT_0x02:      type tag indicating INTEGER
        5AB144C5BDD83410:487BF2694CA398E3
        D860D2465E0305DC:EC429BA6F1CF8C59

    * This terminates the Public Key (X9.63 COMPRESSED form)
    * corresponding bitcoin address is:
   12bFMAPz7dhKmLxsoipfUqmCCjqENCDzKb

as you can see, it contains your address in the last line. The script sig is part of a transaction, and the tx is stored in the block chain. So as long as one can read the blockchain, one can finally decompose the tx. The bitcoin wallet just doesn't show the details you were asking. I think the command "decoderawtransaction" would help to display the structure.

Oh, there is no need to ask twice or more in different forums (https://bitcointalk.org/index.php?topic=2187720.0). This is meaningless bloat...

Not the answer you're looking for? Browse other questions tagged or ask your own question.