Bitcoin Forum
May 13, 2024, 12:40:49 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoin Transaction Size And Fee Calculation  (Read 348 times)
vad_crypto (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 1


View Profile
May 21, 2019, 09:13:12 AM
Merited by mocacinno (1)
 #1

Hey guys
Im building an app using Bitoind and a couple of other crypto core Nodes
I see that some times if i have not enough crypto on one account , it will take some from another account.
for example if i have Global Balance of 2.5 btc on my wallet and i have two accounts x=1.5 (btc) and account y =1 (btc)
im sending from account y 1 btc it takes from x the fee for that transaction leaving my Y account in minus...
Can any one explain why it happends?
How to calculate Transaction size?
How to calculate Transaction fee?
all that before sending the actual transaction to the network , so that i could prevent the address getting into minus balance
Thaks in advance!
1715604049
Hero Member
*
Offline Offline

Posts: 1715604049

View Profile Personal Message (Offline)

Ignore
1715604049
Reply with quote  #2

1715604049
Report to moderator
1715604049
Hero Member
*
Offline Offline

Posts: 1715604049

View Profile Personal Message (Offline)

Ignore
1715604049
Reply with quote  #2

1715604049
Report to moderator
1715604049
Hero Member
*
Offline Offline

Posts: 1715604049

View Profile Personal Message (Offline)

Ignore
1715604049
Reply with quote  #2

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

Posts: 1715604049

View Profile Personal Message (Offline)

Ignore
1715604049
Reply with quote  #2

1715604049
Report to moderator
NeuroticFish
Legendary
*
Offline Offline

Activity: 3668
Merit: 6388


Looking for campaign manager? Contact icopress!


View Profile
May 21, 2019, 09:26:58 AM
Last edit: May 21, 2019, 11:05:52 AM by NeuroticFish
Merited by dbshck (4), ABCbits (1)
 #2

A transaction has to pay the miner fee in order to get processed.
The fee depends on the transaction size and the minimum fee it 1 sat/byte. A transaction gets some inputs (money you have received) and creates some outputs (money sent out). The transaction size depends on the number of inputs and outputs, you can see at the end of this page: https://wiki.bitcoin.com/w/Transaction_fee https://bitcoin.stackexchange.com/questions/1195/how-to-calculate-transaction-size-before-sending-legacy-non-segwit-p2pkh-p2sh
The minimum fee is 1 sat/byte, but depending on hos busy the network is, your wallet may suggest a bigger fee to make sure the transaction gets processed in meaningful time (currently that's 150 sat/byte!)
Also if your 1 BTC you want to send out came from 10000 small transactions, the fee will be quite big.

If you don't tell your wallet to use certain address (or addresses) to send from (how you do that depends on the wallet software), it will choose by itself.

Bitcoin wiki ( https://en.bitcoin.it/wiki/Miner_fees ) contains a list of useful links to pages that estimate the fee you should use. I find https://btc.com/stats/unconfirmed-tx the easiest to read (or I've got used to it), but I use to adjust the fee based on how busy the graph is, how big are the variations and the time passed since the last few mined blocks.

Edit: added a better link

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
vad_crypto (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 1


View Profile
May 21, 2019, 09:53:04 AM
 #3

Thanks for the reply
Ok all that I get but in the Bicoind Node they have Accounts and i have only one Address connected to one Account.
and the method i use is "sendfrom" which gets Account,address im sending to , amount in btc
.. how could it be that it takes some of the crypto from another address that isnt connected to that account at all.
Is there documentation on how the Nodes work inside how they choose addresses, store and prepare transactions?
Is there a way of detecting network speed without third party?
thanks again
mocacinno
Legendary
*
Online Online

Activity: 3388
Merit: 4922


https://merel.mobi => buy facemasks with BTC/LTC


View Profile WWW
May 21, 2019, 10:01:49 AM
 #4

Do you mean you're using bitcoin core's account feature?

Maybe it would be interesting to read following release notes https://bitcoin.org/en/release/v0.17.0

In detail, following subsection might be interesting to you:

Quote
A new ‘label’ API has been introduced for the wallet. This is intended as a replacement for the deprecatedaccount’ API. The ‘account’ can continue to be used in V0.17 by starting bitcoind with the ‘-deprecatedrpc=accounts’ argument, and will be fully removed in V0.18.

source: https://bitcoin.org/en/release/v0.17.0

I've never used the account feature myself, but i've seen several people getting confused with this deprecated feature and reporting errors... Best not to use it.
Also: there is no such thing as an actual negative balance... It's only because the account feature doesn't work properly... So you'll probably have a negative balance for one account matching a positive balance for a different account...

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
vad_crypto (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 1


View Profile
May 21, 2019, 03:35:40 PM
 #5

ok ill see into upgrading to the newest version
do you know how do i calculate the number of inputs in my transaction to calculate the size?
bitmover
Legendary
*
Offline Offline

Activity: 2296
Merit: 5942


bitcoindata.science


View Profile WWW
May 21, 2019, 05:58:47 PM
 #6

ok ill see into upgrading to the newest version
do you know how do i calculate the number of inputs in my transaction to calculate the size?

There are some websites like this one to calculate fees for your inputs/output
https://www.buybitcoinworldwide.com/fee-calculator/

The total number of inputs depend on how many Unspent Transaction Output (UTXO) you have in your addresses.

Let's suppose you received 0.001 BTC for 10 weeks. You will then have d 0.01 BTC , but 10 utxo , which would result in 10inputs.
The more inputs you have, more bytes your transaction will have , and higher fees.

A made a post about it recently

What matters for fees is not how many addresses you have, but how many inputs you have.
.....
Every transaction made from your address will now have cost based on every input, individually, when you want to move them.

That´s why it´s important to consolidate your small inputs when fees are low.

If you consolidate your 20 0,0005 BTC with 2 sat/byte, it will be much cheaper than making a transaction now for 20 inputs with 60 sat/byte.

Take a look at LoyceV guide about it:
Fees are low, use this opportunity to Consolidate your small inputs!

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
mocacinno
Legendary
*
Online Online

Activity: 3388
Merit: 4922


https://merel.mobi => buy facemasks with BTC/LTC


View Profile WWW
May 21, 2019, 05:59:06 PM
 #7

ok ill see into upgrading to the newest version
do you know how do i calculate the number of inputs in my transaction to calculate the size?

Just a remark: my post wasn't urging you to upgrade... It was warning you the account function is depreciated and will be removed in 0.18 (the latest version).

About the fee: if you create and sign a tx in the cli of bitcoind, you can always decode the signed tx before you broadcast. You'll get a json that shows you both size and vsize. If you don't like the fee in sat/vbyte, you can skip the broadcasting and re-create a tx with a better fee in sat/vbyte

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
May 22, 2019, 02:20:24 AM
Merited by NeuroticFish (1), ABCbits (1)
 #8

Is there a way of detecting network speed without third party?
If you mean... how to detect how "busy" the network is... you have commands like getmempoolinfo

You will get a return like this:
Code:
{
  "size": 21264,
  "bytes": 12742316,
  "usage": 43390480,
  "maxmempool": 300000000,
  "mempoolminfee": 0.00001000,
  "minrelaytxfee": 0.00001000
}
You can see there are currently over 21,000 unconfirmed transactions.


As for ways to estimate fees, you have estimaterawfee and estimatesmartfee

You might want to look into those, noting of course that they are just "estimates" and no guarantee that the returned "fee rate" will result in confirmation in the specified number of blocks... then you can use settxfee to set the applicable fee rate... and then simply let the wallet work out the total fee for you when you create the transaction.

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
vad_crypto (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 1


View Profile
May 22, 2019, 09:47:36 AM
 #9

Thanks for the info:) very helpful
can you help me understand what is happening in the wallet?
So I have accounts (for now) each account is just a collection of private keys that it controls and they can: create addresses, send crypto to where ever... or even I can move these private keys from one account to another.
But what if I want to send crypto from a specific address, not account. can it be done?
I'm building a multi-user app and I want to save on fees so I want users to send to a couple of addresses that I manage and control. and when I want to send the funds I want to choose the best suitable address and send from it.
mocacinno
Legendary
*
Online Online

Activity: 3388
Merit: 4922


https://merel.mobi => buy facemasks with BTC/LTC


View Profile WWW
May 22, 2019, 09:54:27 AM
 #10

Thanks for the info:) very helpful
can you help me understand what is happening in the wallet?
So I have accounts (for now) each account is just a collection of private keys that it controls and they can: create addresses, send crypto to where ever... or even I can move these private keys from one account to another.
But what if I want to send crypto from a specific address, not account. can it be done?
I'm building a multi-user app and I want to save on fees so I want users to send to a couple of addresses that I manage and control. and when I want to send the funds I want to choose the best suitable address and send from it.


yes... It can be done

In the gui => coin controll
In the cli (or json-rpc) => "listunspent" to see unspent outputs => "createrawtransaction" to create a transaction using these unspent outputs => "signrawtransaction" to sign the raw transaction => "sendrawtransaction" to broadcast the signed tx

You'll have to combine the cli sollution with "decoderawtransaction" to look at the vsize and "estimatesmartfee" to see which fee is appropriate at that time. Oh, and the "getrawchangeaddress" to create a new change address (don't overspend on fees by not sending the change to a change addy!!!)

Both sollutions (gui with coin controll and/or cli) would also allow you to send funds to multiple addresses (users) in one transaction, increasing the size of the transaction, but still saving on fees because 1 transaction combining many unspent outputs as input and generating many new unspent outputs as output is smaller than several transactions combining less unspent outputs as input and creating 1 (or 2) new outputs (don't forget the change address)

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
vad_crypto (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 1


View Profile
May 22, 2019, 01:08:10 PM
 #11

great:)
can i some how check the balance of the Public or Private Keys through RPC or CLI cos I did?
mocacinno
Legendary
*
Online Online

Activity: 3388
Merit: 4922


https://merel.mobi => buy facemasks with BTC/LTC


View Profile WWW
May 22, 2019, 01:13:06 PM
 #12

great:)
can i some how check the balance of the Public or Private Keys through RPC or CLI cos I did?

the method "listunspent" returns an array of unspent outputs, for each output the txid, vout, address,.., amount,... will be returned. It's up to you to create a sum of all amounts for each address. You'll need the txid and vout in order to create a raw transaction btw...

There's also the method "getreceivedbyaddress"

The big difference between the two is that the first method (using listunspent) will return a lot of information you'll need when creating a new transaction (tx, vout, number of unspent outputs) but you'll have to calculate the sum yourself (but, in all fairness, if you don't know how to do this, you shouldn't be working on a project to begin with Wink ), while on the other hand getreceivedbyaddress will give you a "simple" result... Just a value indicating the total amount in btc that was received by the address you queryd

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
NeuroticFish
Legendary
*
Offline Offline

Activity: 3668
Merit: 6388


Looking for campaign manager? Contact icopress!


View Profile
May 22, 2019, 01:35:07 PM
 #13

It may worth mentioning that GetReceivedByAddress doesn't count Coinbase Transactions. Probably OP will not be affected by this, still, you never know...

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
vad_crypto (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 1


View Profile
May 23, 2019, 04:33:36 AM
 #14

yeah also ive noticed that "getreceivedbyaddress" doesnt return the accurate address. it returns only the amount received and not the balance the list unspent will return the actual balance of an acoccount if the summ is counted.
vad_crypto (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 1


View Profile
May 23, 2019, 04:59:52 AM
 #15

Do you have any recent documentation about bitcoin node functionality and architecture somewhere? because I could find only old stuff and not very detailed.
mocacinno
Legendary
*
Online Online

Activity: 3388
Merit: 4922


https://merel.mobi => buy facemasks with BTC/LTC


View Profile WWW
May 23, 2019, 05:33:19 AM
 #16

Do you have any recent documentation about bitcoin node functionality and architecture somewhere? because I could find only old stuff and not very detailed.
You have the developer reference here:
https://bitcoin.org/en/developer-reference

Or the git repo here:
https://github.com/bitcoin/

And even the complete sourcecode here:
https://github.com/bitcoin/bitcoin

Good luck!

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
vad_crypto (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 1


View Profile
May 23, 2019, 06:14:43 AM
 #17

great.thanks:) don't think I will not ask you any more questions though lol
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!