New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to estimate tx fee? #126
Comments
Hi, I am a bit confused about what you are trying to do. Bit will automatically create a change output in the transaction so you don't lose anything. You may try to use key.send(...) and if you don't have enough balance it will return an error message. You can get your balance via |
Let's say I received 0.87035 BTC and I need to send 0.87 BTC to an address + the rest to another address. I need to know if I'll be able to send 0.87 BTC, pay the fees and send the rest to another address or if I need to send less than 0.87 BTC to pay the fees (and thus not have rest). I need to know the exact fee, right? |
Is the other address your own bit address? In your example, you very likely will be able to send, because the minimum fee in bitcoin is 1 sat/byte and 35000 satoshis will cover the fee of a 35 kB transaction. Whether or not that transaction will confirm fast is a whole different issue. You can get an idea of what will left like this: from bit.transaction import select_coins
selected_unspents, rest = select_coins(87000000, 1, [34], min_change=566, unspents=key.get_unspents()) The value feerate = 5 # your choice
selected_unspents, rest = select_coins(87000000, feerate, [34], min_change=566, unspents=key.get_unspents()) |
Nope the other address is not mine: my app is basically a middleman for a transaction. Edit: this might does the job: https://bitcoin.stackexchange.com/a/3011 |
34 is the size (in bytes) of the outputs and min_change is the minimum amount of change you want to have in your change (the minimum is 566 satoshis, this is called the dust limit). If you want to send what is left to another person you can use the key.send([('A', 87000000)], fee=1,leftover='B') |
Okay, sorry to bother you with all these questions and thank you very much for your help! What's the change exactly? |
From the past question, unspents are UTXOs. If you have 1 bitcoin and you want to send 0.1 BTC to someone, you send 0.1 BTC to that person and 0.9 BTC to yourself. The 0.9 BTC output is known as change. What is your app by the way? |
Oh okay so the change is the leftover, right? If I don't send the leftover to my own address, I don't have a change, is that it? |
Yes, the leftover argument is the change. if you don't set the |
Yeah but I meant, if I set the leftover to another address, this is basically like any other output, isn't it? |
not exactly because the fee is deducted from that output, so you don't know exactly how much it will be... contrary to the outputs in the output list where you know the exact amount they will receive |
@Th0rgal is this solved? maybe close this issue? |
You are right, sorry 🙂 |
Hello,
I know the content of a balance, a quantity and I have 3 outputs: A, B and C and I'm using a segwit address. My quantity is at least equals to my balance.
if my balance is superior enough to my quantity:
else:
My question is: how to detect my balance is sufficient to send the rest of the quantity, pay the fees and add a leftover?
I looked into the code and found this:
bit/bit/transaction.py
Line 180 in defa2e6
But I don't understand how to use it (I think it is not in the documentation).
Thanks for your help,
Thomas
The text was updated successfully, but these errors were encountered: