Author

Topic: bitcoin transactions size and multiple output... (Read 2024 times)

jr. member
Activity: 51
Merit: 2
December 18, 2015, 01:53:14 AM
#15
DannyHamilton, Thank you Smiley
I am very grateful for your assistance.

Quote
If you are using Bitcoin Core, then you can use "listunspent" to get the list of all unspent outputs that the wallet has full control over.  You could also use "getrawtransaction" and/or "decoderawtransaction" to get information about specific transactions if you know the transactionID.

Now (7.30 AM France), my Bitcoin Core deamon is downloading the blockchain ( 345379 of 388985 blocks downloaded...),
transaction is
Quote
"block_height":387184
so I have to wait that it download that block to test it Smiley

I will have to study now,
- how to determine size of transaction before create it (to determine the appropriate fees)
- create it with CreateRawTransaction
- sign it with SignRawTransaction
- send it with SendRawTransaction

Thank you for you help Wink
legendary
Activity: 3472
Merit: 4801
- snip -
for exemple, if I want to spend the 0.04999 of this address : (that I have the private keys of course...) https://blockchain.info/address/1g89wGhWxuQGGqGxVG6dZMzTTSVMWqWj6 to an empty new address

You'll notice that this address has received only 1 transaction.  The transaction ID where the bitcoins were received (where the output was created) was:
8dc0aa6a5022868490245fd4b10c47bccdaa0358cb24ed5ad3d09c99fac39f0e

If you look at that transaction you can see the outputs:

https://blockchain.info/rawtx/8dc0aa6a5022868490245fd4b10c47bccdaa0358cb24ed5ad3d09c99fac39f0e?format=json
Code:
{
   "ver":1,
   "inputs":[
      {
         "sequence":4294967295,
         "prev_out":{
            "spent":true,
            "tx_index":114922410,
            "type":0,
            "addr":"17foftVDmgZr5pawBG9isJJPjnKbSKyM2t",
            "value":4284390417,
            "n":1,
            "script":"76a91449278511d5dd5fac30738bfea348822cb690277588ac"
         },
         "script":"47304402204c187e6420ab27127f35e007c537ac60a431a767ccce67d35e6741dc0606beb00220602b8dac48444943b63793370c4ab91c444cfe09e27d433ab14596f6febcf3520141047d53cd75d37054ba2b3212f9b0251323e618480b3cd247c5b36e1546b87b8e702095803a5ce683e0b1ecddc02c1c5ce4c19fda589c625c901787bf66e9fa0844"
      }
   ],
   "block_height":387184,
   "relayed_by":"127.0.0.1",
   "out":[
      {
         "spent":false,
         "tx_index":114922761,
         "type":0,
         "addr":"1g89wGhWxuQGGqGxVG6dZMzTTSVMWqWj6",
         "value":4999000,
         "n":0,
         "script":"76a914076631c59ba595332917d7b6705006345233e46388ac"
      },
      {
         "spent":true,
         "tx_index":114922761,
         "type":0,
         "addr":"17foftVDmgZr5pawBG9isJJPjnKbSKyM2t",
         "value":4279381417,
         "n":1,
         "script":"76a91449278511d5dd5fac30738bfea348822cb690277588ac"
      }
   ],
   "lock_time":0,
   "size":257,
   "double_spend":false,
   "time":1449506781,
   "tx_index":114922761,
   "vin_sz":1,
   "hash":"8dc0aa6a5022868490245fd4b10c47bccdaa0358cb24ed5ad3d09c99fac39f0e",
   "vout_sz":2
}

Notice from that JSON output that there are two outputs ("out" array with two array elements).  The first output of the array is the one sent to "addr" 1g89wGhWxuQGGqGxVG6dZMzTTSVMWqWj6.  The index is indicated in the blockchain.info web interface in the array element with the "n" label.  So in this case, it is array element 0.

{
      "spent":false,
      "tx_index":114922761,
      "type":0,
      "addr":"1g89wGhWxuQGGqGxVG6dZMzTTSVMWqWj6",
      "value":4999000,
      "n":0,
      "script":"76a914076631c59ba595332917d7b6705006345233e46388ac"
},

How you determine this in your software will depend what interface you are using to access the data.  There are several services with their own API that you could use, or you could just use the Bitcoin Core interface.

If you are using Bitcoin Core, then you can use "listunspent" to get the list of all unspent outputs that the wallet has full control over.  You could also use "getrawtransaction" and/or "decoderawtransaction" to get information about specific transactions if you know the transactionID.

after done with CreateRawTransaction, is the next steps :
> SignRawTransaction > SendRawTransaction
or just
>  SendRawTransaction ?

An unsigned transaction is not a valid transaction.  All nodes will reject it, and miners will not confirm it.  Therefore, you will need to use "signrawtransaction" before you can "sendrawtransaction"

jr. member
Activity: 51
Merit: 2
Thank you DannyHamilton for your clear explanation Smiley , with your help, now I understand good that SendMany is not what I need because it works with accounts ans not with address Smiley
 
I would like to test CreateRawTransaction
https://bitcoin.org/en/developer-reference#createrawtransaction,

for exemple, if I want to spend the 0.04999 of this address : (that I have the private keys of course...) https://blockchain.info/fr/address/1g89wGhWxuQGGqGxVG6dZMzTTSVMWqWj6 to an empty new address

php code
Code:
$bitcoin->createrawtransaction(
    array(
        array(
            "txid"=>"8dc0aa6a5022868490245fd4b10c47bccdaa0358cb24ed5ad3d09c99fac39f0e",
            "vout"=>? //how can I get it?        ),
           ),
    array(
        "1GTDT3hYk4x4wzaa9k38pRsHy9SPJ7qPzT"=>0.04999,
            )
);

I can't find where I can get the output index vout ?

bitcoin devlopper reference quote :  https://bitcoin.org/en/developer-reference#createrawtransaction
Quote
The createrawtransaction RPC creates an unsigned serialized transaction that spends a previous output to a new output with a P2PKH or P2SH address. The transaction is not stored in the wallet or transmitted to the network.

after done with CreateRawTransaction, is the next steps :
> SignRawTransaction > SendRawTransaction
or just
>  SendRawTransaction ?

I thank you for your help and hope I will too help another newbie in future, like you help me
legendary
Activity: 3472
Merit: 4801
But know what I can't understand, is why are this additional input and outputs?

I make these three transactions with RPC calls to bitcoind server, using sendmany method.
In these three exmples, I always give to server just 2 outputs (receiving address), from an account, and transfert exactly the amount of bitcoin from the account (without fee), but know it appaears that there is more input and outputs as I expected...

Do you know why?

Sendmany does not allow you to choose which outputs the wallet will use.  If you want to specify exactly which outputs you want the wallet to use, then you need to use createrawtransaction.

"Addresses" and "accounts" are not the same thing.  Bitcoin Core has a built in accounting system that doesn't work the way most people seem to think that it would work. Think of it more like a bank where the "account name" in Bitcoin Core is like our account number at the bank, and the "bitcoin address" is like our receipt number on our bank transaction.  It is possible for receipt numbers and account numbers to have the same value occasionally, but that doesn't mean they are the same thing.  If the bank is using their interface properly, then we should get a new receipt number for every transaction we do, but our account numbers stay the same.  If I make five transactions depositing a $20 bill into the bank each time, the bank will have received five outputs that they will store in the safe. If you deposit ten $10 bills into the bank, the bank will have a total of fifteen outputs that they will store in the safe (five from me and ten from you).  Now, if you come back and withdraw $100, the bank won't keep track of which of those paper notes are yours and which are mine, they'll just go grab some of the $20 and some of the $10 to give you, and then they'll adjust the values in your account.

Just like you can overdraw your account at a bank, it is possible for you to overdraw your account in Bitcoin Core.  If you have 0.5 BTC in account A in Bitcoin Core, and 0.75 BTC in account B, then Bitcoin Core will allow you to use sendmany to send 1.0 BTC from account A.  The balance on account A will then be -0.5 BTC and the balance on account B will still be 0.75 BTC.

I don't think that sendmany will allow you to set a transaction fee (or lack of fee) either.  It will just use whatever the default fee settings are for the wallet.
jr. member
Activity: 51
Merit: 2
Thank you Knightdk and DannyHamilton for your answer.
It's really clear now.

I will study it for know the size of a transaction before create it.

But know what I can't understand, is why are this additional input and outputs?

I make these three transactions with RPC calls to bitcoind server, using sendmany method.
In these three exmples, I always give to server just 2 outputs (receiving address), from an account, and transfert exactly the amount of bitcoin from the account (without fee), but know it appaears that there is more input and outputs as I expected...

Do you know why?
staff
Activity: 3458
Merit: 6793
Just writing some code
Also, compressed public keys will begin with a 02 or 03 byte while uncompressed public keys begin with a 04 byte.

True, but if you've gotten that far, then you must already have gotten past the key size.
It is a lot easier to just look for that. In most block explorers, the scriptsig is already broken into the sig and the pubkey. They are usually separated by a space, and the pubkey is the second one. Just quickly looking at the first byte can tell you whether it is compressed or not. Even where the scriptsig is not broken apart, most transactions use sighash all, which is a 01 byte at the end of the sig. I usually look for a that 01 in the middle and if it is followed by any of the leading bytes for a pubkey, then in most cases you will have found the pubkey and then you can know which type it is.
legendary
Activity: 3472
Merit: 4801
Also, compressed public keys will begin with a 02 or 03 byte while uncompressed public keys begin with a 04 byte.

True, but if you've gotten that far, then you must already have gotten past the key size.
staff
Activity: 3458
Merit: 6793
Just writing some code
thank you knightdk for your answer but how do you know if the key is compressed or not ?

If the wallet created the address, then it will know what type of address it created.  If you wrote your own software for generating addresses, then you should know what type of address you generated.

If you can access the private key for an address, then you can tell if it is a compressed key address by the first byte in the private key.

A private key in WIF for an uncompressed key address on testnet will start with a 9.

A private key in WIF for a compressed key address on testnet will start with a c.

If you don't have access to the private key, but you have access to a transaction where the the output has been spent (and if it was a pay-to-pubkey-hash output) , then you can tell by looking at the scriptSig (also known as Txin-script).

The first byte of the scriptSig indicates the length (in bytes) of the signature, next is the signature, then the next byte after the signature is a byte that indicates the length of the public key.  If the length of the public key is 65 bytes (41 in hex), then the input was previously received at an uncompressed key address.  If the length of the public key is 33 bytes (21 in hex), then the input was previously received at a compressed key address.


Also, compressed public keys will begin with a 02 or 03 byte while uncompressed public keys begin with a 04 byte.
legendary
Activity: 3472
Merit: 4801
thank you knightdk for your answer but how do you know if the key is compressed or not ?

If the wallet created the address, then it will know what type of address it created.  If you wrote your own software for generating addresses, then you should know what type of address you generated.

If you can access the private key for an address, then you can tell if it is a compressed key address by the first byte in the private key.

A private key in WIF for an uncompressed key address on testnet will start with a 9.

A private key in WIF for a compressed key address on testnet will start with a c.

If you don't have access to the private key, but you have access to a transaction where the the output has been spent (and if it was a pay-to-pubkey-hash output) , then you can tell by looking at the scriptSig (also known as Txin-script).

The first byte of the scriptSig indicates the length (in bytes) of the signature, next is the signature, then the next byte after the signature is a byte that indicates the length of the public key.  If the length of the public key is 65 bytes (41 in hex), then the input was previously received at an uncompressed key address.  If the length of the public key is 33 bytes (21 in hex), then the input was previously received at a compressed key address.

legendary
Activity: 3472
Merit: 4801
In the exemple2, I send 0.067 from 5  adress with 1 input in each
from :
to 2 address (no fees, no change address exatly like exemple1)
0.06633 for mhtqrsyrT2TKE5ZVCKTVGZM63L8L9W4jq6
0.00067 for n1ZkUoqCMEFXA5KboJHNuSaNDL7iP2LiWd

You are mistaken.

I've looked at the transaction you posted.

It appears to have 6 inputs, not 5 inputs:
  • Output 1 from transaction 071f1301d51d4f1915527412e4cb345e297ce9fa1225b685a9f5eddd7cf90b91 supplying 0.013 BTC
  • Output 1 from transaction ab4d6036bb9d372c06dec648b960290e934675cc399f3c6b29f6d0f17b415cfb supplying 0.013 BTC
  • Output 1 from transaction a17df58e6fb16f575f0c5e578c06f615340671c4507355aac8d045e5adda51d9 supplying 0.014 BTC
  • Output 0 from transaction bef8a7b4ee76d0992c2fa471f77e1c90ad6bac913a0f6a8b072037297efa70f7 supplying 0.013 BTC
  • Output 0 from transaction 87b10237194cf8b83beabae22309826e26ebcd61fd5467fdfdc10bf52c4aeed5 supplying 0.014 BTC
  • Output 2 from transaction 605ad738e124aa9a6fe2e1a1e9873309c72e02e6b2d676ed0a237304ad6e644f supplying 0.01782863 BTC

For a total of 0.08482863 BTC in value supplied to the transaction

It also appears to have 3 outputs, not 2:
  • 0.0175239 sent to msYuu7v4SdKeexEcg3NenaeugRykE1FihH
  • 0.06633 sent to mhtqrsyrT2TKE5ZVCKTVGZM63L8L9W4jq6
  • 0.00067 sent to n1ZkUoqCMEFXA5KboJHNuSaNDL7iP2LiWd

For a total of 0.0845239 BTC in value spent from the transaction

Leaving 0.00030473 BTC as a transaction fee

One of your inputs (the one from transaction 605ad738e124aa9a6fe2e1a1e9873309c72e02e6b2d676ed0a237304ad6e644f) was received at a compressed key address.

So, that's a minimum size of:
(5*180)+(1*148)+(3*34)+10-6 = 1154

And a maximum size of:
(5*180)+(1*148)+(3*34)+10+6 = 1166


The size you have is: 1157

1154 < 1157 < 1166

I haven't looked at Example 3 yet, but I suspect that you probably made similar errors.
jr. member
Activity: 51
Merit: 2
thank you knightdk for your answer but how do you know if the key is compressed or not ?
and what is then the formula for exemple2 and 3?

thank you for answer
staff
Activity: 3458
Merit: 6793
Just writing some code
Example 1 uses inputs that use uncompressed keys, so they are longer and fit the formula that you used

Examples 2 and 3 both have some inputs that use compressed keys so those inputs are shorter. You will need to use their shorter size when adding calculating those inputs. Their size is 148 bytes, 32 bytes shorter than the inputs that use uncompressed keys.
jr. member
Activity: 51
Merit: 2
thank you for your answer Smiley , I work with testcoins

In the exemple1, I send 0.064
from mhrUjndTCeu6yicvwrsy68GxtQrGKCcwVr (that have exatly 0.064)
to 2 address: (no fees, no change address...)
0.06336 for mhtqrsyrT2TKE5ZVCKTVGZM63L8L9W4jq6
0.00064 for n1ZkUoqCMEFXA5KboJHNuSaNDL7iP2LiWd

the transaction hex decode :
Code:
{
    "addresses": [
        "mxtPpWyow8gmop56Lk4xikYDkGEFtMJA6P",
        "msYuu7v4SdKeexEcg3NenaeugRykE1FihH",
        "mhtqrsyrT2TKE5ZVCKTVGZM63L8L9W4jq6",
        "n1ZkUoqCMEFXA5KboJHNuSaNDL7iP2LiWd",
        "mptiFufnzE5ZF3asUDf2ErQGoHzvEvwUfR",
        "mhrUjndTCeu6yicvwrsy68GxtQrGKCcwVr"
    ],
    "block_height": -1,
    "block_index": -1,
    "confidence": 0,
    "confirmations": 0,
    "double_spend": false,
    "fees": 10858,
    "hash": "23d2b0dcd8ec0e455c223f5a8f417b4cd29f745ae8287a6ef539d29ecc1e8d31",
    "inputs": [
        {
            "addresses": [
                "mhrUjndTCeu6yicvwrsy68GxtQrGKCcwVr"
            ],
            "age": 36,
            "output_index": 1,
            "output_value": 1300000,
            "prev_hash": "0324bbe9b2af51e7812a09fc702f6ee2dc2d99a5f2490d808c421e9c7e2f4521",
            "script": "473044022056a72f75a94215b47116e5d33a890279eb7880bce22b2954977baf48a24e604a022026ea68e9114881f4adb2c305725d10edc6bbc39d77cf1568cbbca3f9daabd0440141041e21e40a7929ce00e18573b8ef928e217829563ea0526c54c2e8b96452e96b4d88ca0b3012b10d64ab09d769eb5ded8c644afbb00f213585fb9f1af1f9897db3",
            "script_type": "pay-to-pubkey-hash",
            "sequence": 4294967294
        },
        {
            "addresses": [
                "mxtPpWyow8gmop56Lk4xikYDkGEFtMJA6P"
            ],
            "age": 237,
            "output_index": 1,
            "output_value": 1800000,
            "prev_hash": "e621196a7de3668bc5cafafd889efcaea54063ee4339ddc71a283cba78d5bc38",
            "script": "483045022100c450913409515799fc4a6c5ea56f0e4c42bad08b7343518eaec31c7436f8e2a802205f28dfb1a3093bdac39c6b401bcce61ce852314376eb1d66c10deb539e9b105b014104362600287cf5946804b153ac7516a3557679815d785df6f2228c291ef58c41ea4677bd792a5fc2e3a35dee6ed5ace22d36f116e387f760e5816cdc082f8c467a",
            "script_type": "pay-to-pubkey-hash",
            "sequence": 4294967294
        },
        {
            "addresses": [
                "mhrUjndTCeu6yicvwrsy68GxtQrGKCcwVr"
            ],
            "age": 36,
            "output_index": 0,
            "output_value": 1300000,
            "prev_hash": "294b3a352e71d6f964e130647a90044df5c33f253aebd89563c832f8840a138c",
            "script": "483045022100ecaeb8eb6133534263c5124ac3eea82473ac62a9070f0044c40e9399cb919575022069cde8992a18617ab9f117a6974853a401b986452c9fa5cb16d16b34b44029330141041e21e40a7929ce00e18573b8ef928e217829563ea0526c54c2e8b96452e96b4d88ca0b3012b10d64ab09d769eb5ded8c644afbb00f213585fb9f1af1f9897db3",
            "script_type": "pay-to-pubkey-hash",
            "sequence": 4294967294
        },
        {
            "addresses": [
                "mhrUjndTCeu6yicvwrsy68GxtQrGKCcwVr"
            ],
            "age": 36,
            "output_index": 0,
            "output_value": 1300000,
            "prev_hash": "a3512f0f2f9e96aebac32e9db1f63d2b383360875e19540f7a0ad1e95698fbe5",
            "script": "47304402205f4e8b6bbd520da3a5e98433c2c2aa6b3261fcdd589d4a0955a20537da41421102204f2f1975f5260a2b3ea97ea693d3b705a5618ad1053f80cb37c5ee8aa21f4c370141041e21e40a7929ce00e18573b8ef928e217829563ea0526c54c2e8b96452e96b4d88ca0b3012b10d64ab09d769eb5ded8c644afbb00f213585fb9f1af1f9897db3",
            "script_type": "pay-to-pubkey-hash",
            "sequence": 4294967294
        },
        {
            "addresses": [
                "msYuu7v4SdKeexEcg3NenaeugRykE1FihH"
            ],
            "age": 39,
            "output_index": 0,
            "output_value": 1752390,
            "prev_hash": "6f274e7a50aa9f7964ec164e1e7c45908851706521575c06cf36fc2406aa428a",
            "script": "4730440220149a990c9599b22a39df12390ab2d9d040ef7957a0642176718710e6559a0893022052ee3849d906ba39a03cdb3661379764c19f55583f82b70c055a04446b1db56a0121021c58fa6f542d40af02208b54e68737cce627634db83bedfb94da39d079dfcd3c",
            "script_type": "pay-to-pubkey-hash",
            "sequence": 4294967294
        }
    ],
    "lock_time": 626558,
    "outputs": [
        {
            "addresses": [
                "mhtqrsyrT2TKE5ZVCKTVGZM63L8L9W4jq6"
            ],
            "script": "76a9141a1408281c0e0547e5371b6c0435f705d6ae40bd88ac",
            "script_type": "pay-to-pubkey-hash",
            "value": 6336000
        },
        {
            "addresses": [
                "n1ZkUoqCMEFXA5KboJHNuSaNDL7iP2LiWd"
            ],
            "script": "76a914dbe9e6b7f1c8ee638ac536131546a2bfa5bbbede88ac",
            "script_type": "pay-to-pubkey-hash",
            "value": 64000
        },
        {
            "addresses": [
                "mptiFufnzE5ZF3asUDf2ErQGoHzvEvwUfR"
            ],
            "script": "76a91466d690d3955017f389ae3e4ace08a0aec5f2505588ac",
            "script_type": "pay-to-pubkey-hash",
            "spent_by": "bb904d66068ef0cfc3e6d8b2153e3f1b8a4375d9a19740d7f110d8b02bcd75e0",
            "value": 1041532
        }
    ],
    "preference": "low",
    "received": "2015-12-16T15:28:50.697314744Z",
    "relayed_by": "54.147.180.40, 127.0.0.1",
    "size": 977,
    "total": 7441532,
    "ver": 1,
    "vin_sz": 5,
    "vout_sz": 3
}


---------------------------------------------------------------------------------------------

In the exemple2, I send 0.067 from 5  adress with 1 input in each
from :
mhmXbBpwznLvtdtMe4pXomUW6pB1Z1Tjx9 0.014
mpUdk8WCCv7X2Na9VNc1B7mPouDHdp3qNC 0.014
miA5yJeoqRsn7FSjnu88rB49niqVmFKvjK 0.013
n2R4xyw5Hws3KcWA932nTKXYbnVx8RWt8K 0.013
mshVq1kSb9cYeMswVQ4bo63U1fLfqYQk9w 0.013
----> total 0.067
to 2 address (no fees, no change address exatly like exemple1)
0.06633 for mhtqrsyrT2TKE5ZVCKTVGZM63L8L9W4jq6
0.00067 for n1ZkUoqCMEFXA5KboJHNuSaNDL7iP2LiWd

the decode transaction hex :

Code:
{
    "addresses": [
        "mshVq1kSb9cYeMswVQ4bo63U1fLfqYQk9w",
        "mhmXbBpwznLvtdtMe4pXomUW6pB1Z1Tjx9",
        "n2R4xyw5Hws3KcWA932nTKXYbnVx8RWt8K",
        "mgqGzhZpHZSxLvnvcNkNgm5xbnE5FjNB32",
        "n1ZkUoqCMEFXA5KboJHNuSaNDL7iP2LiWd",
        "miA5yJeoqRsn7FSjnu88rB49niqVmFKvjK",
        "mpUdk8WCCv7X2Na9VNc1B7mPouDHdp3qNC",
        "msYuu7v4SdKeexEcg3NenaeugRykE1FihH",
        "mhtqrsyrT2TKE5ZVCKTVGZM63L8L9W4jq6"
    ],
    "block_height": -1,
    "block_index": -1,
    "confidence": 0,
    "confirmations": 0,
    "double_spend": false,
    "fees": 30473,
    "hash": "6f274e7a50aa9f7964ec164e1e7c45908851706521575c06cf36fc2406aa428a",
    "inputs": [
        {
            "addresses": [
                "miA5yJeoqRsn7FSjnu88rB49niqVmFKvjK"
            ],
            "age": 40,
            "output_index": 1,
            "output_value": 1300000,
            "prev_hash": "071f1301d51d4f1915527412e4cb345e297ce9fa1225b685a9f5eddd7cf90b91",
            "script": "483045022100f84ce596df3f5370c5256f3292139a4fb79f540e43f4d117b2e71d4991ac544102206e71fba5fb805eb32dc4aca41ec955d74ec41eb10bf462493532bf6d6724978e014104b7ecc1f94329e903ac1cfccdfe11018972024f1ddc7b12b55bfc7755844d40c1e92dc2a783d2ee55b60a19658eb82d727783ba6b53a0c0335a3b72be709376c0",
            "script_type": "pay-to-pubkey-hash",
            "sequence": 4294967294
        },
        {
            "addresses": [
                "mshVq1kSb9cYeMswVQ4bo63U1fLfqYQk9w"
            ],
            "age": 40,
            "output_index": 1,
            "output_value": 1300000,
            "prev_hash": "ab4d6036bb9d372c06dec648b960290e934675cc399f3c6b29f6d0f17b415cfb",
            "script": "483045022100ee8d32e402bfffd4ab81726c5d5a0aa089cc7f1736c1911e11d709714976e0230220722190da15f5047cd51ce7119c4a83f388347f153567bb5c6772e0c2252558630141049e5b05cfb03aabfc1ef2c5a6627e097a38077dc333e97fa072ee1129323a0cebe7e1eeb5ae32789a20c340f61852938b9be972ad18d40d95edc793b813df85a5",
            "script_type": "pay-to-pubkey-hash",
            "sequence": 4294967294
        },
        {
            "addresses": [
                "mhmXbBpwznLvtdtMe4pXomUW6pB1Z1Tjx9"
            ],
            "age": 40,
            "output_index": 1,
            "output_value": 1400000,
            "prev_hash": "a17df58e6fb16f575f0c5e578c06f615340671c4507355aac8d045e5adda51d9",
            "script": "48304502210089ee9b5446cbb17e0ac0b6fe9de5e9a9c94091cf0148b7261da578de4c0741e602205f7499383a55283347cd453b091f933005e13c74544f3503998cf103f3b915df0141046c56182691c0e2adf716e788108305f916f224b652dc4375a48758c02703e648f406849b308fe8768372250fcb552889948c2cc55ed5b1bd899fb69dc0803527",
            "script_type": "pay-to-pubkey-hash",
            "sequence": 4294967294
        },
        {
            "addresses": [
                "n2R4xyw5Hws3KcWA932nTKXYbnVx8RWt8K"
            ],
            "age": 40,
            "output_index": 0,
            "output_value": 1300000,
            "prev_hash": "bef8a7b4ee76d0992c2fa471f77e1c90ad6bac913a0f6a8b072037297efa70f7",
            "script": "47304402203bbb8cad97a60854c660076e003331b334311bc148a7f8a06e79b2198c2f7cd202204aa9cfdfb249e45e442db53994d3e30a4261fa5bf7650826eec72cc9e38e946d014104c90695fc2894f7175eb893d1b57b364db76f1a8ced116618fd70c40dbdc3cb7bb94d4582f13dc580525c856224486e4f98e410a8f5be4e0fb9c8ab54bc7a5703",
            "script_type": "pay-to-pubkey-hash",
            "sequence": 4294967294
        },
        {
            "addresses": [
                "mpUdk8WCCv7X2Na9VNc1B7mPouDHdp3qNC"
            ],
            "age": 40,
            "output_index": 0,
            "output_value": 1400000,
            "prev_hash": "87b10237194cf8b83beabae22309826e26ebcd61fd5467fdfdc10bf52c4aeed5",
            "script": "47304402203c606eccca77891067c4f21ebd505a6aae99d6273997e8f863c599015b2cdafa02207f5c01eb4501d9de315cb046257746b8cb256c3fda2af91d65859c28ec54b67d01410491faa92745655bd2185eff4e21569996e02c4432f2ee0466375e50906f652836c8ae9a633d970271f5ec84c740e7fb9a83f5ed93b6edec4d00d936b4942a81ad",
            "script_type": "pay-to-pubkey-hash",
            "sequence": 4294967294
        },
        {
            "addresses": [
                "mgqGzhZpHZSxLvnvcNkNgm5xbnE5FjNB32"
            ],
            "age": 49,
            "output_index": 2,
            "output_value": 1782863,
            "prev_hash": "605ad738e124aa9a6fe2e1a1e9873309c72e02e6b2d676ed0a237304ad6e644f",
            "script": "4730440220614eaebd1935e5c00c0fe602d41bf2ed67a03f4df7f83946dae373e3e408ee5d022047df6b03e224664d2ae7aceafb11d6f8917269d909f90800d7f512f0557c4d6d0121039712b30d49cf4e2017fbbc4ac7d18684a5f76654b7efeb3d7c19d5aed0a507a3",
            "script_type": "pay-to-pubkey-hash",
            "sequence": 4294967294
        }
    ],
    "lock_time": 626552,
    "outputs": [
        {
            "addresses": [
                "msYuu7v4SdKeexEcg3NenaeugRykE1FihH"
            ],
            "script": "76a9148400577c2b2c07033613c8e0d207775e1fee274888ac",
            "script_type": "pay-to-pubkey-hash",
            "spent_by": "23d2b0dcd8ec0e455c223f5a8f417b4cd29f745ae8287a6ef539d29ecc1e8d31",
            "value": 1752390
        },
        {
            "addresses": [
                "mhtqrsyrT2TKE5ZVCKTVGZM63L8L9W4jq6"
            ],
            "script": "76a9141a1408281c0e0547e5371b6c0435f705d6ae40bd88ac",
            "script_type": "pay-to-pubkey-hash",
            "value": 6633000
        },
        {
            "addresses": [
                "n1ZkUoqCMEFXA5KboJHNuSaNDL7iP2LiWd"
            ],
            "script": "76a914dbe9e6b7f1c8ee638ac536131546a2bfa5bbbede88ac",
            "script_type": "pay-to-pubkey-hash",
            "value": 67000
        }
    ],
    "preference": "medium",
    "received": "2015-12-16T15:16:17.37632399Z",
    "relayed_by": "54.147.180.40, 127.0.0.1",
    "size": 1157,
    "total": 8452390,
    "ver": 1,
    "vin_sz": 6,
    "vout_sz": 3
}


-------------------------------------------------------------------------------------------------

In the exemple3, I send 0.011 from 1  adress with 1 input  
from :
n12oErzdFKYWtyVrymmyPezjby1pdJ3tSK 0.011

----> total 0.011
to 2 address (no fees, no change address exatly like exemple1 and 2)
0.01089 for mhtqrsyrT2TKE5ZVCKTVGZM63L8L9W4jq6
0.00011 for n1ZkUoqCMEFXA5KboJHNuSaNDL7iP2LiWd

the decode transaction hex :
Code:
{
    "addresses": [
        "n1ZkUoqCMEFXA5KboJHNuSaNDL7iP2LiWd",
        "moaAacfHEdD1avNkaxemmiDT8W3Q8FEWGT",
        "mhrUjndTCeu6yicvwrsy68GxtQrGKCcwVr",
        "mptiFufnzE5ZF3asUDf2ErQGoHzvEvwUfR",
        "mhtqrsyrT2TKE5ZVCKTVGZM63L8L9W4jq6"
    ],
    "block_height": -1,
    "block_index": -1,
    "confidence": 0,
    "confirmations": 0,
    "double_spend": false,
    "fees": 4881,
    "hash": "bb904d66068ef0cfc3e6d8b2153e3f1b8a4375d9a19740d7f110d8b02bcd75e0",
    "inputs": [
        {
            "addresses": [
                "mhrUjndTCeu6yicvwrsy68GxtQrGKCcwVr"
            ],
            "age": 36,
            "output_index": 1,
            "output_value": 1200000,
            "prev_hash": "21fec8941bf4c1d5bc16aa8bb512891e48d54b4bd12e39c3b9b5e3ce596964cd",
            "script": "47304402205b35bfac235fe72916e8595197a1131a3496eed7b0a237407f3e3410c152d332022054770f5d4cc2ad40895bde1dc6ff8e7608f492f7962e228eac1b3000acba22b60141041e21e40a7929ce00e18573b8ef928e217829563ea0526c54c2e8b96452e96b4d88ca0b3012b10d64ab09d769eb5ded8c644afbb00f213585fb9f1af1f9897db3",
            "script_type": "pay-to-pubkey-hash",
            "sequence": 4294967294
        },
        {
            "addresses": [
                "mptiFufnzE5ZF3asUDf2ErQGoHzvEvwUfR"
            ],
            "age": 33,
            "output_index": 2,
            "output_value": 1041532,
            "prev_hash": "23d2b0dcd8ec0e455c223f5a8f417b4cd29f745ae8287a6ef539d29ecc1e8d31",
            "script": "483045022100f6a2d52fbf382283224ed8131347eef23ed0cc6d370fca606a21480f9e31329002204565c3d88f58bab5f27cd41dcd15ace062b6527b23e5e8a2554ecb90be965db801210383ad804a57b5e32a6831bd7f950070d3b7bb62393b1daabb8e3e7edc74ea4222",
            "script_type": "pay-to-pubkey-hash",
            "sequence": 4294967294
        }
    ],
    "lock_time": 626563,
    "outputs": [
        {
            "addresses": [
                "mhtqrsyrT2TKE5ZVCKTVGZM63L8L9W4jq6"
            ],
            "script": "76a9141a1408281c0e0547e5371b6c0435f705d6ae40bd88ac",
            "script_type": "pay-to-pubkey-hash",
            "value": 1089000
        },
        {
            "addresses": [
                "n1ZkUoqCMEFXA5KboJHNuSaNDL7iP2LiWd"
            ],
            "script": "76a914dbe9e6b7f1c8ee638ac536131546a2bfa5bbbede88ac",
            "script_type": "pay-to-pubkey-hash",
            "value": 11000
        },
        {
            "addresses": [
                "moaAacfHEdD1avNkaxemmiDT8W3Q8FEWGT"
            ],
            "script": "76a914585c8275f35b0df2b5475cf5ff62d324b924dce888ac",
            "script_type": "pay-to-pubkey-hash",
            "spent_by": "fa3a0d02b8a332975b85ced543650bb9fdbb505dd81197c4930fcbba3dfad119",
            "value": 1136651
        }
    ],
    "preference": "low",
    "received": "2015-12-16T15:24:16.519825263Z",
    "relayed_by": "54.147.180.40, 127.0.0.1",
    "size": 439,
    "total": 2236651,
    "ver": 1,
    "vin_sz": 2,
    "vout_sz": 3
}
legendary
Activity: 3472
Merit: 4801
You'll have to provide actual examples.  Show what the resulting actual transactions are so we can see where you made your error.

I think that formula only works for pay-to-pubkey-hash addresses, addresses that start with a 1 (on mainnet) or with an m or n (on testnet).  If you are using inputs that were sent to pay-to-script-hash addresses, addresses that start with a 3 (on mainnet) or with 2 (on testnet), then the calculation will be different.

Also note that the formula that you've indicated is for inputs that were received at addresses computed from uncompressed keys.  Using compressed key addresses reduces the size of each input by about 32 bytes. If those inputs were received at addresses computed from compressed keys, then I think the formula is:

Code:
in*148 + out*34 + 10 plus or minus 'in'
jr. member
Activity: 51
Merit: 2
Hi
I have a little problem to determine a bitcoin transaction size...

I read this topic https://bitcointalksearch.org/topic/question-about-transaction-size-1000686 ,and this too : http://bitcoin.stackexchange.com/questions/1195/how-to-calculate-transaction-size-before-sending but it seem not work for my case...

I create a transaction that have always min 2 outputs ( without the change address it will be 3)

I understand this : in*180 + out*34 + 10 plus or minus 'in' but I try with different type of transactions :




in the below exemple the transaction is sending bitcoin to 2 different address (with sendmany)



-- first exemple
from 1 address with 5 inputs -> size : 977

(5*180) + (2*34) +10 +-5 = 900 + 68 + 10 +-5 = 978+-5
 973 < size (977 ) < 983 it's okay! Smiley



-- second exemple
from 5 differents address with in each 1 input -> size : 1157

it appaers that for the formula work it could just be :

(5*180) + (7*34) + 10 +- 5*2 = 900 + 238 + 10 +- 10 = 1148 +- 10
1138 < size 1157 < 1158

is that right? if yes, why here 7 outputs? why *2 ??



-- third exemple
from 1 address with 1 input -> size : 439

it appaers that for the formula work it could just be :

(2*180) + (2*34) + 10 +- 1 = 360 + 68 + 10 +- 1 = 360 + 68 + 10 +- 1 = 438 = 437 < size 439 < 439

why here this 2 when there is just one input?


could anyone help for explain me why this differences? Thank you for your help Smiley
Jump to: