Bitcoin Forum
May 13, 2024, 04:24:35 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to calculate inputs and outputs?  (Read 288 times)
MakFrogz (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 1


View Profile
May 21, 2019, 03:35:08 PM
 #1

Hi!

How to calculate inputs and outputs before sending transaction?
1715574275
Hero Member
*
Offline Offline

Posts: 1715574275

View Profile Personal Message (Offline)

Ignore
1715574275
Reply with quote  #2

1715574275
Report to moderator
1715574275
Hero Member
*
Offline Offline

Posts: 1715574275

View Profile Personal Message (Offline)

Ignore
1715574275
Reply with quote  #2

1715574275
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715574275
Hero Member
*
Offline Offline

Posts: 1715574275

View Profile Personal Message (Offline)

Ignore
1715574275
Reply with quote  #2

1715574275
Report to moderator
1715574275
Hero Member
*
Offline Offline

Posts: 1715574275

View Profile Personal Message (Offline)

Ignore
1715574275
Reply with quote  #2

1715574275
Report to moderator
1715574275
Hero Member
*
Offline Offline

Posts: 1715574275

View Profile Personal Message (Offline)

Ignore
1715574275
Reply with quote  #2

1715574275
Report to moderator
bitmover
Legendary
*
Offline Offline

Activity: 2296
Merit: 5942


bitcoindata.science


View Profile WWW
May 21, 2019, 06:32:28 PM
 #2

I think you maybe confused about what are inputs and outputs.

When you receive a some BTC, every transaction you receive in an address generate an utxo. When you wanna send that utxo, each one of them is going to be counted as one input , no matter how many addresses you have.

If you received 0.01 BTC in 5 transactions, you will have 5 inputs in your transaction.

The output is the destination. If you want to send all those inputs to one address, there will be one output. However if you don't want to send all your balance, there will be two outputs (Onde of the will be a new address in your wallet, a change address, for the change)

Input

An input is a reference to an output from a previous transaction. Multiple inputs are often listed in a transaction. All of the new transaction's input values (that is, the total coin value of the previous outputs referenced by the new transaction's inputs) are added up, and the total (less any transaction fee) is completely used by the outputs of the new transaction. Previous tx is a hash of a previous transaction.

Output

An output contains instructions for sending bitcoins. Value is the number of Satoshi (1 BTC = 100,000,000 Satoshi) that this output will be worth when claimed. ScriptPubKey is the second half of a script (discussed later). There can be more than one output, and they share the combined value of the inputs. Because each output from one transaction can only ever be referenced once by an input of a subsequent transaction, the entire combined input value needs to be sent in an output if you don't want to lose it. If the input is worth 50 BTC but you only want to send 25 BTC, Bitcoin will create two outputs worth 25 BTC: one to the destination, and one back to you (known as "change", though you send it to yourself). Any input bitcoins not redeemed in an output is considered a transaction fee; whoever generates the block can claim it by inserting it into the coinbase transaction of that block.

https://en.bitcoin.it/wiki/Transaction


So,how do you calculate how many inputs you have to consume all your funds in an address?
Just take a look way your address in any block explorer. The amount of incoming transactions that still have balances is your total inputs, as every transaction generates one utxo (which is one input)

The output are just the number of destination addresses. Usually just 2 (destination address and change address)

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
o_e_l_e_o
In memoriam
Legendary
*
Offline Offline

Activity: 2268
Merit: 18512


View Profile
May 22, 2019, 08:53:59 PM
 #3

Based on OP's other thread started here (https://bitcointalk.org/index.php?topic=5145649.0), I suspect he is asking about how to calculate transaction size prior to sending.

There are two ways you can do this. One is doing it manually, using your knowledge of what kind of inputs you are using and a calculator such as this one: https://www.coinb.in/#fees
The second way is to simply plug your transaction in to a wallet like Electrum and hit "Preview". The total size in bytes will be calculated for you.
buwaytress
Legendary
*
Offline Offline

Activity: 2800
Merit: 3447


Join the world-leading crypto sportsbook NOW!


View Profile
May 23, 2019, 10:31:48 AM
 #4

This is one of the reasons I like using Electrum, for a lightweight client that is to me the so easy to get into for a newbie, it takes away all the size calculations needed, and still has relatively enough flexibility to control and choose which inputs to use, relative fees. etc.

This was my go-to formula:
- number of inputs you're using, a
- number of outputs you'll create, b

Then: a*180 + b*34 + 10 +/- 1.

As achow101 pointed out, there would be a slight variation if you're using old clients that used uncompressed pubkey then the multiplier would be 148.

I haven't figured out the exact adjustments for Segwit... so I guess Electrum made me lazy.

██
██
██
██
██
██
██
██
██
██
██
██
██
... LIVECASINO.io    Play Live Games with up to 20% cashback!...██
██
██
██
██
██
██
██
██
██
██
██
██
o_e_l_e_o
In memoriam
Legendary
*
Offline Offline

Activity: 2268
Merit: 18512


View Profile
May 23, 2019, 11:20:02 AM
Merited by buwaytress (1)
 #5

Then: a*180 + b*34 + 10 +/- 1.

As achow101 pointed out, there would be a slight variation if you're using old clients that used uncompressed pubkey then the multiplier would be 148.
I think you've misunderstood achow101's post. An uncompressed pubkey is larger, hence the multiplier of 180. Almost all wallets now use a compressed pubkey, which takes up less space at 148.

For SegWit, take a look at this post from Pieter Wuille: https://bitcoin.stackexchange.com/questions/87275/how-to-calculate-segwit-transaction-fee-in-bytes/87276#87276. The calculator at https://www.coinb.in/#fees also includes SegWit inputs and outputs.
buwaytress
Legendary
*
Offline Offline

Activity: 2800
Merit: 3447


Join the world-leading crypto sportsbook NOW!


View Profile
May 23, 2019, 05:38:38 PM
 #6

Then: a*180 + b*34 + 10 +/- 1.

As achow101 pointed out, there would be a slight variation if you're using old clients that used uncompressed pubkey then the multiplier would be 148.
I think you've misunderstood achow101's post. An uncompressed pubkey is larger, hence the multiplier of 180. Almost all wallets now use a compressed pubkey, which takes up less space at 148.

For SegWit, take a look at this post from Pieter Wuille: https://bitcoin.stackexchange.com/questions/87275/how-to-calculate-segwit-transaction-fee-in-bytes/87276#87276. The calculator at https://www.coinb.in/#fees also includes SegWit inputs and outputs.

My mistake indeed! Thanks for the clarification, that's def the case. It's really amazing how efficient we're getting, and I've only been properly using Bitcoin for under 3 years. Leaps and bounds.

Yeah, the coinb calculator really useful, and that's a 1st world problem for me, all these tools make my life so easy there's less need to go down to the raw numbers.

But Bull's Eye on the link to Pieter's formula! That's the sort of thing that makes us go to bed happy. Nice share.

██
██
██
██
██
██
██
██
██
██
██
██
██
... LIVECASINO.io    Play Live Games with up to 20% cashback!...██
██
██
██
██
██
██
██
██
██
██
██
██
o_e_l_e_o
In memoriam
Legendary
*
Offline Offline

Activity: 2268
Merit: 18512


View Profile
May 23, 2019, 07:05:03 PM
 #7

all these tools make my life so easy there's less need to go down to the raw numbers.
Exactly. Rare are the times I need to calculate an exact transaction size prior to making it, but since I use Electrum it is far quicker to just set up the transaction in there and see what it tells me rather than sitting down and working it out for myself. I know it's lazy but hey, my time is valuable. Cheesy
yegor256
Member
**
Offline Offline

Activity: 224
Merit: 15

Creator of Zold


View Profile WWW
May 26, 2019, 10:51:38 AM
 #8

You may find this video relevant: https://www.youtube.com/watch?v=IV9pRBq5A4g

And this blog post of mine: https://www.yegor256.com/2019/05/07/sibit-bitcoin-command-line-client.html

Creator of Zold / click here to buy a few!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!